Пример #1
0
 private static void MoveDames(int x, int y, FieldState fieldState, GameState gameState)
 {
     if (fieldState != gameState.CurrentDame) return;
     for (var i = 0; i < 8; i++) MovePawn(x, y, x + i, y + i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x + i, y - i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x - i, y - i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x - i, y + i, gameState);
 }
Пример #2
0
 private static void CapturePawns(FieldState[,] boardState, int x, int y, GameState gameState)
 {
     if (boardState[x, y] != gameState.CurrentPawn) return;
     CapturePawn(boardState, x, y, 1, 1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, 1, -1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, -1, -1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, -1, 1, gameState, gameState.CurrentPawn);
 }
Пример #3
0
 private static void CaptureDames(FieldState[,] boardState, int x, int y, GameState gameState)
 {
     if (boardState[x, y] != gameState.CurrentDame) return;
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, i, i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, i, -i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, -i, -i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, -i, i, gameState, gameState.CurrentDame);
 }
Пример #4
0
 private static void MovePawns(int x, int y, FieldState fieldState, GameState gameState)
 {
     if (fieldState != gameState.CurrentPawn) return;
     var direction = 0;
     if (fieldState == FieldState.RedPawn) direction = 1;
     if (fieldState == FieldState.YellowPawn) direction = -1;
     MovePawn(x, y, x + direction, y + 1, gameState);
     MovePawn(x, y, x + direction, y - 1, gameState);
 }
Пример #5
0
 private static void MovePawn(int currentX, int currentY, int newX, int newY, GameState gameState)
 {
     if (newX < 0 || newX > 7 || newY < 0 || newY > 7) return;
     if (gameState.PreviousBoardArray[newX, newY] != FieldState.Empty) return;
     var tmpBoard = (FieldState[,])gameState.PreviousBoardArray.Clone();
     tmpBoard[newX, newY] = tmpBoard[currentX, currentY];
     tmpBoard[currentX, currentY] = FieldState.Empty;
     gameState.PossibleMoves.Add(tmpBoard);
 }
Пример #6
0
        public static void SetPossibleCapture(FieldState[,] boardState, GameState gameState)
        {
            gameState.PossibleCapture.Clear();

            for (var i = 0; i < 8; i++)
                for (var j = 0; j < 8; j++)
                {
                    CapturePawns(boardState, i, j, gameState);
                    CaptureDames(boardState, i, j, gameState);
                }
        }
Пример #7
0
        public static void SetPossibleMoves(GameState gameState)
        {
            gameState.PossibleMoves.Clear();

            for (var i = 0; i < 8; i++)
                for (var j = 0; j < 8; j++)
                {
                    var fieldState = gameState.PreviousBoardArray[i, j];
                    MovePawns(i, j, fieldState, gameState);
                    MoveDames(i, j, fieldState, gameState);
                }
        }
Пример #8
0
        private static void CapturePawn(FieldState[,] boardState, int currentX, int currentY, int moveX, int moveY, GameState gameState, FieldState currentPawnType)
        {
            var opponentPawnX = currentX + moveX;
            var opponentPawnY = currentY + moveY;
            var opponentPawn = gameState.CurrentPawn == FieldState.RedPawn ? FieldState.YellowPawn : FieldState.RedPawn;
            var opponentDame = gameState.CurrentDame == FieldState.BluePawn ? FieldState.GreenPawn : FieldState.BluePawn;
            var newX = currentX + (moveX > 0 ? moveX + 1 : moveX - 1);
            var newY = currentY + (moveY > 0 ? moveY + 1 : moveY - 1);

            if ((boardState[currentX, currentY] != currentPawnType) ||
                (opponentPawnX < 0 || opponentPawnX > 7 || opponentPawnY < 0 || opponentPawnY > 7) ||
                (newX < 0 || newX > 7 || newY < 0 || newY > 7) ||
                !((boardState[opponentPawnX, opponentPawnY] == opponentPawn) || (boardState[opponentPawnX, opponentPawnY] == opponentDame)) ||
                (boardState[newX, newY] != FieldState.Empty))
                return;

            var tmpBoard = (FieldState[,])boardState.Clone();
            tmpBoard[newX, newY] = tmpBoard[currentX, currentY];
            tmpBoard[currentX, currentY] = FieldState.Empty;
            tmpBoard[opponentPawnX, opponentPawnY] = FieldState.Empty;
            gameState.PossibleCapture.Add(tmpBoard);
        }
Пример #9
0
 public void InitBoard(FieldState[,] boardArray)
 {
     _gameState = new GameState(boardArray);
     Console.WriteLine("Init new Board");
     Console.WriteLine("Current player: {0}", _gameState.CurrentPlayer + 1);
 }
Пример #10
0
 public CheckCheckers()
 {
     _gameState = new GameState();
 }