三目並べゲームに取り組んでいて、undoメソッドを実装したいと思っています。これを行うための最良の方法は、別の(複数の?)スタックをセットアップし、実行されたばかりの「移動」のコピーを作成することです。次に、undoが呼び出された場合は、最後の動きをポップして、ゲームボードに再入力します。
そうそう、私は考えを持っていますが、それを実装する方法を理解することはできません。
私が持っているもののいくつか:
設定するには:
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つ続けてチェックする方法があります。
アドバイスありがとうございます