Beispiel #1
0
 /* This takes a value indicating a gameModel and returns the values of the displayable
 and game models and utilities to null. */
 public void UnInitialiseModel(EGameModels model)
 {
     switch(model)
     {
         case EGameModels.Chess:
             chessModel = null;
             evaluator = null;
             break;
         case EGameModels.TicTacToe:
             tictactoeModel = null;
             break;
     }
     displayableGameModel = null;
     gameState = EGameControlState.PreInitial;
 }
Beispiel #2
0
        /* Take a valid-format move object and check if it may be legally
        applied to the current chess game. It must pass the following checks:
        -the locations are distinct and
        -the A tile contains a piece of the current player
        Also one of the following:
            -the B tile contains a piece of the current player (further castle checks) or
            -the B tile contains a piece of the opponent player (further capture checks) or
            -the B tile is empty:
                -(further en passant checks)
                -(further movement checks)
        Finally it must check, if the move were to be applied, that it does not leave the
        current player's king in check.*/
        public bool IsValidMove(ref FormedMove move, ChessPositionModel cpm, ref List<Tuple<int, int>> kingCheckedBy)
        {
            bool validMove = false;
            Tile tileA = new Tile();
            Tile tileB = new Tile();

            if (IsMovePositionsDistinct(move))
            {
                if (IsMoveAPieceCurPlayer(move, cpm, ref tileA))
                {
                    // check if its a castling
                    if (IsMoveBPieceCurPlayer(move, cpm, ref tileB))
                    {
                        validMove = false; // IsLegalCastle? - this involves calls to isKingInCheck
                        move.MoveType = EChessMoveTypes.Castle;
                    }
                    // check if its a capture
                    else if (IsMoveBPieceOtherPlayer(move, cpm, ref tileB))
                    {
                        validMove = IsCaptureLegal(move, cpm);
                        move.MoveType = EChessMoveTypes.Capture;
                    }
                    // check if its a movement
                    else if (IsMoveBEmpty(move, cpm, ref tileB))
                    {
                        if (validMove = IsPieceMovementLegal(move, cpm))
                        {
                            move.MoveType = EChessMoveTypes.Movement;
                        }
                        else if (validMove = IsEnPassantCaptureLegal(move, cpm))
                        {
                            move.MoveType = EChessMoveTypes.EpMovement;
                        }
                    }
                }
            }
            // if its a valid move so far, check if there is a pawn promotion,
            // then apply the move to a copy of the chess position and
            // finally check it passes a check test
            if (validMove)
            {
                // if there is a pawn promotion the player is prompted for the promotion piece and it is added to the move object
                MoveIncludesPawnPromotion(ref move, cpm);

                // a copy of the chess position is made so that the move may
                // be applied in order for the king-check to be checked without
                // causing the chess position to update the display
                ChessPosition cpCopy = cpm.getChessPositionCopy();
                cpCopy.applyMove(move);
                // after this application of the move
                if (IsKingInCheck(cpCopy, ref kingCheckedBy))
                    validMove = false;
            }
            return validMove;
        }
Beispiel #3
0
 /* Receives a value indicating a game model and sets up the model as
 'displayableModel' (to which the view is bound) and also
 '*Model' (which is used in the game loop etc). This method also
 sets up any dependent utilities. */
 public void InitialiseModel(EGameModels model, System.Windows.Forms.Form viewRef)
 {
     switch(model)
     {
         case EGameModels.Chess:
             displayableGameModel = new ChessPositionModel();
             chessModel = (ChessPositionModel)displayableGameModel;
             evaluator = new Evaluator();
             evaluator.ViewRef = viewRef;
             evaluator.GenerateRays();
             evaluator.GeneratePawnRays();
             break;
         case EGameModels.TicTacToe:
             displayableGameModel = new TicTacToePositionModel();
             tictactoeModel = (TicTacToePositionModel)displayableGameModel;
             break;
     }
     gameState = EGameControlState.Initial;
 }