我正在开发一个井字游戏,我想实现一个撤消方法。我认为最好的方法是设置另一个(多个?)堆栈,并复制刚刚发生的“移动”。然后,如果调用了撤消,只需弹出最后一步并重新填充游戏板。
所以是的,我有这个想法,但无法弄清楚如何实现它。
我拥有的一些东西:
设置:
public void set(Position p, int v, int n) throws IOException {
if (board[p.x][p.y][p.z]!= 0) throw new IOException("Position taken");
//Restrict 222 until all other's have been used
if (n != 26) {
if (p.x == 1 && p.y == 1 && p.z ==1) {
throw new IOException("[2,2,2] cannot be played until all other positions have been taken");
}
}
//Enforce x=1 for first 9, x=3 for next 9
if (n < 9 ) {
if (p.x != 0) throw new IOException("Please play on x=1 for the first 9 moves");
}
if (n >= 9 && n < 18) {
if (p.x != 2) throw new IOException("Please play on x=3 for the first 9 moves");
}
board[p.x][p.y][p.z] = v;
}
然后是板法搭建板子,展示法,当然还有一个连续检查3个的方法。
感谢您的任何建议