From 4e8f554286593ec8aca6c61fa0fb9c4934bd640c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 13 Jul 2018 17:06:48 -0400 Subject: Redesigned the solver algorithm The new solver algorithm decreases the size of the search space by combining states. A flood fill is used to find all of the positions accessible by the player without changing the board state, and that flood is considered a node in the search graph, rather than there being a node for every position on every board state. Other optimizations are implemented too, like checking for changes locally instead of using tick, and using unordered_map/unordered_set because bitsets are hashable. Also changed wrap to use references, finally. refs #1 --- util.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'util.cpp') diff --git a/util.cpp b/util.cpp index 5ccfe51..9fcdbbd 100644 --- a/util.cpp +++ b/util.cpp @@ -2,22 +2,22 @@ #include "mazeoflife.h" #include -void wrap(int* x, int* y) +void wrap(int& x, int& y) { - if (*x < 0) + if (x < 0) { - *x = WIDTH-(0-*x); - } else if (*x >= WIDTH) + x = WIDTH+x; + } else if (x >= WIDTH) { - *x = *x-WIDTH; + x = x-WIDTH; } - if (*y < 0) + if (y < 0) { - *y = HEIGHT-(0-*y); - } else if (*y >= HEIGHT) + y = HEIGHT+y; + } else if (y >= HEIGHT) { - *y = *y-HEIGHT; + y = y-HEIGHT; } } -- cgit 1.4.1