|
|
|
@ -15,7 +15,7 @@ namespace Reversi
@@ -15,7 +15,7 @@ namespace Reversi
|
|
|
|
|
private int whiteSafeCount; |
|
|
|
|
private System.Int32[,] squares; |
|
|
|
|
private System.Boolean[,] safeDiscs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int BlackCount { |
|
|
|
|
get { return blackCount; } |
|
|
|
|
} |
|
|
|
@ -37,7 +37,46 @@ namespace Reversi
@@ -37,7 +37,46 @@ namespace Reversi
|
|
|
|
|
public int WhiteSafeCount { |
|
|
|
|
get { return whiteSafeCount; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Board() |
|
|
|
|
{ |
|
|
|
|
// Constructor
|
|
|
|
|
squares = new System.Int32[,](8, 8); |
|
|
|
|
safeDiscs = new System.Boolean[,](8, 8); |
|
|
|
|
for (int i = 0; i < 8; i++) { |
|
|
|
|
for (int j = 0; j < 8; j++) { |
|
|
|
|
squares[i, j] = Empty; |
|
|
|
|
safeDiscs[i, j] = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
UpdateCounts(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Board(Reversi.Board board) |
|
|
|
|
{ |
|
|
|
|
// Constructor
|
|
|
|
|
squares = new System.Int32[,](8, 8); |
|
|
|
|
safeDiscs = new System.Boolean[,](8, 8); |
|
|
|
|
for (int i = 0; i < 8; i++) { |
|
|
|
|
for (int j = 0; j < 8; j++) { |
|
|
|
|
squares[i, j] = board.squares[i, j]; |
|
|
|
|
safeDiscs[i, j] = board.safeDiscs[i, j]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
blackCount = board.blackCount; |
|
|
|
|
whiteCount = board.whiteCount; |
|
|
|
|
emptyCount = board.emptyCount; |
|
|
|
|
blackSafeCount = board.blackSafeCount; |
|
|
|
|
whiteSafeCount = board.whiteSafeCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Board() |
|
|
|
|
{ |
|
|
|
|
Black = -1; |
|
|
|
|
Empty = 0; |
|
|
|
|
White = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void SetForNewGame() |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < 8; i++) { |
|
|
|
@ -52,12 +91,12 @@ namespace Reversi
@@ -52,12 +91,12 @@ namespace Reversi
|
|
|
|
|
squares[4, 4] = White; |
|
|
|
|
UpdateCounts(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetSquareContents(int row, int col) |
|
|
|
|
{ |
|
|
|
|
return squares[row, col]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void MakeMove(int color, int row, int col) |
|
|
|
|
{ |
|
|
|
|
squares[row, col] = color; |
|
|
|
@ -74,7 +113,7 @@ namespace Reversi
@@ -74,7 +113,7 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
UpdateCounts(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool HasAnyValidMove(int color) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < 8; i++) { |
|
|
|
@ -86,7 +125,7 @@ namespace Reversi
@@ -86,7 +125,7 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsValidMove(int color, int row, int col) |
|
|
|
|
{ |
|
|
|
|
if (squares[row, col] != Empty) { |
|
|
|
@ -101,7 +140,7 @@ namespace Reversi
@@ -101,7 +140,7 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetValidMoveCount(int color) |
|
|
|
|
{ |
|
|
|
|
int i = 0; |
|
|
|
@ -114,7 +153,7 @@ namespace Reversi
@@ -114,7 +153,7 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsOutflanking(int color, int row, int col, int dr, int dc) |
|
|
|
|
{ |
|
|
|
|
int i = row + dr; |
|
|
|
@ -126,7 +165,7 @@ namespace Reversi
@@ -126,7 +165,7 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateCounts() |
|
|
|
|
{ |
|
|
|
|
blackCount = 0; |
|
|
|
@ -177,18 +216,18 @@ namespace Reversi
@@ -177,18 +216,18 @@ namespace Reversi
|
|
|
|
|
} |
|
|
|
|
if (safeDiscs[i, j]) { |
|
|
|
|
whiteSafeCount++; |
|
|
|
|
goto BasicBlock_327; |
|
|
|
|
goto BasicBlock_381; |
|
|
|
|
} else { |
|
|
|
|
goto BasicBlock_327; |
|
|
|
|
goto BasicBlock_381; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
emptyCount++; |
|
|
|
|
} |
|
|
|
|
BasicBlock_327: |
|
|
|
|
BasicBlock_381: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsOutflankable(int row, int col) |
|
|
|
|
{ |
|
|
|
|
int i = squares[row, col]; |
|
|
|
|