diff --git a/board.h b/board.h index 9a917e8..c03a5f7 100644 --- a/board.h +++ b/board.h @@ -84,12 +84,13 @@ class Board{ }; private: - short size; //the length of one side of the hexagon - short size_d; //diameter of the board = size*2-1 + char size; //the length of one side of the hexagon + char size_d; //diameter of the board = size*2-1 short nummoves; char toPlay; char outcome; //-1 = unknown, 0 = tie, 1,2 = player win + bool allowswap; vector cells; @@ -104,6 +105,7 @@ class Board{ nummoves = 0; toPlay = 1; outcome = -1; + allowswap = true; cells.resize(vecsize()); @@ -143,8 +145,8 @@ class Board{ bool onboard(int x, int y) const { return ( x >= 0 && y >= 0 && x < size_d && y < size_d && onboard_fast(x, y) ); } bool onboard(const Move & m)const { return (m.x >= 0 && m.y >= 0 && m.x < size_d && m.y < size_d && onboard_fast(m) ); } - bool canswap() const { return (nummoves == 1 && toPlay == 2); } -// bool canswap() const { return false; } + void setswap(bool s) { allowswap = s; } + bool canswap() const { return (nummoves == 1 && toPlay == 2 && allowswap); } //assumes x, y are in bounds (meaning no swap) and the game isn't already finished bool valid_move_fast(int x, int y) const { return !get(x,y); } diff --git a/solver.h b/solver.h index 0d13f14..22b18ad 100644 --- a/solver.h +++ b/solver.h @@ -99,11 +99,11 @@ class Solver { } void timedout(){ timeout = true; } - void solve_ab (const Board & board, double time, int mdepth = 1000); - void solve_scout (const Board & board, double time, int mdepth = 1000); - void solve_pns (const Board & board, double time, uint64_t memlimit); - void solve_pnsab (const Board & board, double time, uint64_t memlimit); - void solve_dfpnsab(const Board & board, double time, uint64_t memlimit); + void solve_ab (Board board, double time, int mdepth = 1000); + void solve_scout (Board board, double time, int mdepth = 1000); + void solve_pns (Board board, double time, uint64_t memlimit); + void solve_pnsab (Board board, double time, uint64_t memlimit); + void solve_dfpnsab(Board board, double time, uint64_t memlimit); //protected: diff --git a/solverab.cpp b/solverab.cpp index c765f55..92a14d1 100644 --- a/solverab.cpp +++ b/solverab.cpp @@ -1,12 +1,13 @@ #include "solver.h" -void Solver::solve_ab(const Board & board, double time, int mdepth){ +void Solver::solve_ab(Board board, double time, int mdepth){ reset(); if(board.won() >= 0){ outcome = board.won(); return; } + board.setswap(false); Timer timer = Timer(time, bind(&Solver::timedout, this)); int starttime = time_msec(); diff --git a/solverdfpnsab.cpp b/solverdfpnsab.cpp index 8807d52..341b52a 100644 --- a/solverdfpnsab.cpp +++ b/solverdfpnsab.cpp @@ -1,13 +1,14 @@ #include "solver.h" -void Solver::solve_dfpnsab(const Board & board, double time, uint64_t memlimit){ +void Solver::solve_dfpnsab(Board board, double time, uint64_t memlimit){ reset(); if(board.won() >= 0){ outcome = board.won(); return; } + board.setswap(false); Timer timer = Timer(time, bind(&Solver::timedout, this)); int starttime = time_msec(); diff --git a/solverpns.cpp b/solverpns.cpp index f00ae8f..d5dc0aa 100644 --- a/solverpns.cpp +++ b/solverpns.cpp @@ -8,13 +8,14 @@ * L W L L from the perspective of toplay * U W LT U */ -void Solver::solve_pns(const Board & board, double time, uint64_t memlimit){ +void Solver::solve_pns(Board board, double time, uint64_t memlimit){ reset(); if(board.won() >= 0){ outcome = board.won(); return; } + board.setswap(false); Timer timer = Timer(time, bind(&Solver::timedout, this)); int starttime = time_msec(); diff --git a/solverpnsab.cpp b/solverpnsab.cpp index d08ff43..2aeba85 100644 --- a/solverpnsab.cpp +++ b/solverpnsab.cpp @@ -1,13 +1,14 @@ #include "solver.h" -void Solver::solve_pnsab(const Board & board, double time, uint64_t memlimit){ +void Solver::solve_pnsab(Board board, double time, uint64_t memlimit){ reset(); if(board.won() >= 0){ outcome = board.won(); return; } + board.setswap(false); Timer timer = Timer(time, bind(&Solver::timedout, this)); int starttime = time_msec(); diff --git a/solverscout.cpp b/solverscout.cpp index ce46faf..7abf062 100644 --- a/solverscout.cpp +++ b/solverscout.cpp @@ -1,12 +1,13 @@ #include "solver.h" -void Solver::solve_scout(const Board & board, double time, int mdepth){ +void Solver::solve_scout(Board board, double time, int mdepth){ reset(); if(board.won() >= 0){ outcome = board.won(); return; } + board.setswap(false); Timer timer = Timer(time, bind(&Solver::timedout, this)); int starttime = time_msec();