private static bool GetPointWinner_CheckFieldState(GameStateInternal gameState, uint x, uint y, ref FieldState expectedState) { if (gameState.Inside(x, y)) { FieldState fieldState = gameState.BoardFields[x, y]; if (fieldState == FieldState.Empty) { return(false); } else { if (expectedState == FieldState.Empty) { expectedState = fieldState; return(true); } else if (expectedState != fieldState) { return(false); } } } return(true); }
public GameState Play(FieldCoordinates action) { if (action == FieldCoordinates.Pass) { if (PreviousMove == FieldCoordinates.Pass) { return(new GameState(CurrentPlayer.Opposite, InternalState.Pass())); } else { return(new GameState(FieldCoordinates.Pass, CurrentPlayer.Opposite, InternalState.Pass())); } } else { GameStateInternal nextState = InternalState.Play(action.X, action.Y, CurrentPlayer); if (nextState == null) { throw new Exception(); } else { return(new GameState(action, CurrentPlayer.Opposite, nextState)); } } }
public GameStateInternal(GameStateInternal state) { Ko = FieldCoordinates.Pass; CapturedStones = state.CapturedStones; BoardSize = state.BoardSize; BoardFields = new FieldState[BoardSize, BoardSize]; Array.Copy(state.BoardFields, BoardFields, state.BoardFields.Length); }
public GameStateInternal Play(uint x, uint y, Stone stone) { if (Inside(x, y)) { if (BoardFields[x, y] == FieldState.Empty) { GameStateInternal result = new GameStateInternal(this); uint capturedW = result.RemoveGroupIfHasOneBreath(x - 1, y, stone.Opposite.Color.State); uint capturedE = result.RemoveGroupIfHasOneBreath(x + 1, y, stone.Opposite.Color.State); uint capturedN = result.RemoveGroupIfHasOneBreath(x, y - 1, stone.Opposite.Color.State); uint capturedS = result.RemoveGroupIfHasOneBreath(x, y + 1, stone.Opposite.Color.State); uint capturedStones = capturedN + capturedS + capturedE + capturedW; result.BoardFields[x, y] = stone.Color.State; int breaths = result.MarkGroup(x, y, stone.Color.State); if (breaths > 0) { result.ClearMarkedFields(stone.Color.State, FieldState.Empty); result.CapturedStones.Add(stone, capturedStones); if (capturedStones == 1 && breaths == 1) { if (capturedN > 0) { result.Ko = FieldCoordinates.Get(x, y - 1); } else if (capturedS > 0) { result.Ko = FieldCoordinates.Get(x, y + 1); } else if (capturedE > 0) { result.Ko = FieldCoordinates.Get(x + 1, y); } else if (capturedW > 0) { result.Ko = FieldCoordinates.Get(x - 1, y); } } return(result); } } } return(null); }
public static FieldState GetPointWinner(GameStateInternal gameState, uint x, uint y) { if (gameState.BoardFields[x, y] == FieldState.Empty) { FieldState expectedState = FieldState.Empty; if (GetPointWinner_CheckFieldState(gameState, x + 1, y, ref expectedState) && GetPointWinner_CheckFieldState(gameState, x - 1, y, ref expectedState) && GetPointWinner_CheckFieldState(gameState, x, y + 1, ref expectedState) && GetPointWinner_CheckFieldState(gameState, x, y - 1, ref expectedState)) { return(expectedState); } } return(FieldState.Empty); }
//Dictionary<FieldCoordinates, GameState> allowedActions; public IEnumerable <FieldCoordinates> GetAllowedActions() { //if (allowedActions == null) //{ //Dictionary<FieldCoordinates, GameState> allowedActions = new Dictionary<FieldCoordinates, GameState>(); if (IsFinal == false) { for (byte y = 0; y < InternalState.BoardSize; y++) { for (byte x = 0; x < InternalState.BoardSize; x++) { FieldCoordinates field = FieldCoordinates.Get(x, y); if (field != InternalState.Ko) { GameStateInternal nextState = InternalState.Play(field.X, field.Y, CurrentPlayer); if (nextState != null) { yield return(field); //allowedActions.Add(field, new GameState(field, CurrentPlayer.Opposite, nextState)); } } } } yield return(FieldCoordinates.Pass); //if (PreviousMove == FieldCoordinates.Pass) //{ // allowedActions.Add(FieldCoordinates.Pass, new GameState(CurrentPlayer.Opposite, InternalState.Pass())); //} //else //{ // allowedActions.Add(FieldCoordinates.Pass, new GameState(FieldCoordinates.Pass, CurrentPlayer.Opposite, InternalState.Pass())); //} } //} //return allowedActions.Keys; }
public static bool IsTrueEye(GameStateInternal gameState, uint x, uint y, Stone stone) { int sum = 0; if (gameState.IsOutsideOrHasState(x + 1, y - 1, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x + 1, y, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x + 1, y + 1, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x, y + 1, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x, y - 1, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x - 1, y - 1, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x - 1, y, stone.Color.State)) { sum++; } if (gameState.IsOutsideOrHasState(x - 1, y + 1, stone.Color.State)) { sum++; } return(sum >= 8); }
// Final State private GameState(Stone currentPlayer, GameStateInternal internalState) { PreviousMove = FieldCoordinates.Pass2; CurrentPlayer = currentPlayer; InternalState = internalState; }
private GameState(FieldCoordinates previousMove, Stone currentPlayer, GameStateInternal internalState) { PreviousMove = previousMove; CurrentPlayer = currentPlayer; InternalState = internalState; }
public GameState(uint boardSize) { PreviousMove = null; CurrentPlayer = Stone.Black; InternalState = new GameStateInternal(boardSize); }