Exemplo n.º 1
0
        private GameLogic gamePreparations()
        {
            string player1Name = ReadInput.PlayerName(), player2Name = null;

            GameLogic.eGameMode gameMode = ReadInput.GameMode(player1Name);

            if (gameMode == GameLogic.eGameMode.TwoPlayers)
            {
                player2Name = ReadInput.PlayerName();
            }
            else
            {
                this.m_GameDifficulty = ReadInput.LevelOfDifficulty();
            }

            ReadInput.BoardDimensions(out int boardNumOfRows, out int boardNumOfCols);
            this.m_CardsData.Capacity = boardNumOfRows * boardNumOfCols / 2;
            this.cardsDataInitialization();

            if (gameMode == GameLogic.eGameMode.OnePlayer)
            {
                m_PcPlayerLogic = new GameLogic.Pc(boardNumOfRows, boardNumOfCols);
            }

            return(new GameLogic(boardNumOfRows, boardNumOfCols, gameMode, player1Name, player2Name));
        }
Exemplo n.º 2
0
        private void playGame(GameLogic i_Game)
        {
            eNewGameRequest requestForNewGame;

            do
            {
                printIntroAndRules(i_Game);
                if (i_Game.GameMode == GameLogic.eGameMode.TwoPlayers)
                {
                    do
                    {
                        Ex02.ConsoleUtils.Screen.Clear();
                        turn(i_Game);
                    }while(i_Game.IsGameFinished() == false);
                }
                else
                {
                    playVsPc(i_Game);
                }

                Ex02.ConsoleUtils.Screen.Clear();
                printScoreBoard(i_Game);
                printCurrentBoardGame(i_Game.Data);
                printWinnerOrTie(i_Game);
                requestForNewGame = ReadInput.NewGameRequest();
                if (requestForNewGame == eNewGameRequest.Yes)
                {
                    ReadInput.BoardDimensions(out int boardNumOfRows, out int boardNumOfCols);
                    this.m_CardsData.Capacity = boardNumOfRows * boardNumOfCols / 2;
                    this.cardsDataInitialization();
                    if (i_Game.GameMode == GameLogic.eGameMode.OnePlayer)
                    {
                        this.m_GameDifficulty = ReadInput.LevelOfDifficulty();
                    }

                    i_Game.ResetGame(boardNumOfRows, boardNumOfCols);
                    m_PcPlayerLogic = new GameLogic.Pc(boardNumOfRows, boardNumOfCols);
                }
            }while(requestForNewGame == eNewGameRequest.Yes);
        }
Exemplo n.º 3
0
        private void btn_Start_Click(object sender, EventArgs e)
        {
            if (combobox_Game_Mode.SelectedIndex == 0 || combobox_Game_Mode.SelectedIndex == -1)
            {
                _gameMode = eGameMode.VsComputer;
            }
            else if (combobox_Game_Mode.SelectedIndex == 1)
            {
                _gameMode = eGameMode.VsHuman;
            }
            else
            {
                _gameMode = eGameMode.ComVsCom;
            }

            if (radiobtn_Black.Checked)
            {
                _ownSide = eChessSide.Black;
            }
            else
            {
                _ownSide = eChessSide.White;
            }

            if (radiobtn_Easy.Checked)
            {
                _gameDifficulty = eGameDifficulty.Easy;
            }
            else if (radiobtn_Medium.Checked)
            {
                _gameDifficulty = eGameDifficulty.Normal;
            }
            else
            {
                _gameDifficulty = eGameDifficulty.Hard;
            }

            _timeLimit = (short)integerInput_TimeLimit.Value;
            _timeBonus = (short)integerInput_TimeBonus.Value;
        }
Exemplo n.º 4
0
        private void btn_Newgame_Click(object sender, EventArgs e)
        {
            Form_New_game form_temp = new Form_New_game(_language);

            if (form_temp.ShowDialog() == DialogResult.OK)
            {
                _ownSide        = form_temp._ownSide;
                _gameMode       = form_temp._gameMode;
                _gameDifficulty = form_temp._gameDifficulty;
                this._timeLimit = form_temp._timeLimit;
                this._timeBonus = form_temp._timeBonus;

                if (_gameMode == eGameMode.VsHuman)
                {
                    CreateChessBoard(_ownSide, _gameMode);
                }
                else if (_gameMode == eGameMode.VsComputer)
                {
                    CreateChessBoard(_ownSide, _gameMode, _gameDifficulty);
                }
            }

            form_temp.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Play with computer given State
        /// </summary>
        /// <param name="ownside"></param>
        /// <param name="gamemode"></param>
        /// <param name="gamedifficulty"></param>
        /// <param name="arrState"></param>
        private void CreateChessBoard(eChessSide ownside, eGameMode gamemode, eGameDifficulty gamedifficulty, ChessState[,] arrState)
        {
            if (board != null)
            {
                board.CancelThinking();
                board.Dispose();

                ucCountDownTimer1.StopTimer();
                ucCountDownTimer2.StopTimer();

                ucCountDownTimer1.Min = _timeLimit;
                ucCountDownTimer2.Min = _timeLimit;
                ucCountDownTimer1.Sec = 0;
                ucCountDownTimer2.Sec = 0;
            }
            else
            {
                ucChessPieceEated1 = new Uc_ChessPieceEated(ownside);
                ucChessPieceEated2 = new Uc_ChessPieceEated(ownside);

                ucCountDownTimer1 = new Uc_CountDownTimer();
                ucCountDownTimer2 = new Uc_CountDownTimer();
                ucCountDownTimer1.StopTimer();
                ucCountDownTimer2.StopTimer();

                ucCountDownTimer1.Min = _timeLimit;
                ucCountDownTimer2.Min = _timeLimit;
                ucCountDownTimer1.Sec = 1;
                ucCountDownTimer2.Sec = 1;

                ucCountDownTimer1.TimeOut += new Uc_CountDownTimer.TimeOutHandler(UcCountDownTimer_TimeOut);
                ucCountDownTimer2.TimeOut += new Uc_CountDownTimer.TimeOutHandler(UcCountDownTimer_TimeOut);
            }

            this.SuspendLayout();
            btn_Undo.Enabled      = true;
            btn_Redo.Enabled      = true;
            btn_Savegame.Enabled  = true;
            btn_Savemoved.Enabled = true;
            panel1.Visible        = true;
            panel1.Controls.Clear();

            pnlTimerLeft.Controls.Clear();
            pnlTimerRight.Controls.Clear();
            pnlTimerRight.Visible = true;
            pnlTimerLeft.Visible  = true;
            pnlTimerLeft.Controls.Add(this.ucCountDownTimer1);
            pnlTimerRight.Controls.Add(this.ucCountDownTimer2);
            ucCountDownTimer1.Size     = new Size(110, 35);
            ucCountDownTimer2.Size     = new Size(110, 35);
            ucCountDownTimer1.Location = new Point(8, 8);
            ucCountDownTimer2.Location = new Point(8, 8);
            pnlTimerLeft.Size          = new Size(ucCountDownTimer1.Width + 16, ucCountDownTimer1.Height + 16);
            pnlTimerRight.Size         = pnlTimerLeft.Size;

            Options obj = new Options();

            board = new Uc_ChessBoard(obj.BoardStyle, obj.PieceStyle, ownside, gamemode, gamedifficulty, obj.CellSize, obj.PieceSize, obj.PlaySound, _language, arrState);

            board.MoveMaked += new Uc_ChessBoard.MoveMakedHandler(MoveMaked);
            if (board.GameMode == eGameMode.VsComputer)
            {
                btn_Hint.Enabled = true;
            }
            else
            {
                btn_Hint.Enabled = false;
            }

            Bitmap bmpBackImage = new Bitmap(board.Width, board.Height);

            board.DrawToBitmap(bmpBackImage, board.Bounds);
            board.BackgroundImage = bmpBackImage;
            board.BoardBitmap     = bmpBackImage;

            _notationSize  = (int)((obj.CellSize * 38) / 100);
            this._gameMode = gamemode;
            this._ownSide  = ownside;

            AddNotation(obj.CellSize, ownside);
            board.Location = new Point(_notationSize, _notationSize);

            this.panel1.ClientSize = new Size(obj.CellSize * 8 + _notationSize * 2, obj.CellSize * 8 + _notationSize * 2);
            this.panel1.Controls.Add(board);
            this.MinimumSize = new Size(1000, 230 + obj.CellSize * 8);

            pnlTimerLeft.Location  = new Point(8, 161);
            panel1.Location        = new Point(pnlTimerLeft.Location.X + 2 + pnlTimerLeft.Width, 161);
            pnlTimerRight.Location = new Point(panel1.Location.X + 2 + panel1.Width, panel1.Location.Y + panel1.Height - pnlTimerRight.Height);

            //ChessPieceEated
            pnlChessPieceEated1.Controls.Clear();
            pnlChessPieceEated2.Controls.Clear();
            pnlChessPieceEated1.Visible = true;
            pnlChessPieceEated2.Visible = true;

            if (board.OwnSide == eChessSide.White)
            {
                ucChessPieceEated1.Side       = eChessSide.White;
                pnlChessPieceEated1.BackColor = Color.White;
                ucChessPieceEated2.Side       = eChessSide.Black;
                pnlChessPieceEated2.BackColor = Color.DimGray;
            }
            else
            {
                ucChessPieceEated1.Side       = eChessSide.Black;
                pnlChessPieceEated1.BackColor = Color.DimGray;
                ucChessPieceEated2.Side       = eChessSide.White;
                pnlChessPieceEated2.BackColor = Color.White;
            }

            pnlChessPieceEated1.Size     = new Size(pnlTimerLeft.Size.Width - 45, (pnlTimerLeft.Width - 30) * 4);
            pnlChessPieceEated2.Size     = new Size(pnlTimerRight.Size.Width - 45, (pnlTimerRight.Width - 30) * 4);
            pnlChessPieceEated1.Location = new Point(pnlTimerLeft.Location.X + pnlTimerLeft.Width - pnlChessPieceEated1.Width, pnlTimerLeft.Location.Y + pnlTimerLeft.Height + 10);
            pnlChessPieceEated2.Location = new Point(pnlTimerRight.Location.X, pnlTimerRight.Location.Y - pnlChessPieceEated2.Height - 10);
            ucChessPieceEated1.Size      = new Size(pnlChessPieceEated1.Size.Width, pnlChessPieceEated1.Size.Height);
            ucChessPieceEated2.Size      = new Size(pnlChessPieceEated2.Size.Width, pnlChessPieceEated2.Size.Height);
            pnlChessPieceEated1.Controls.Add(ucChessPieceEated1);
            pnlChessPieceEated2.Controls.Add(ucChessPieceEated2);
            ucChessPieceEated1.LoadChessPieces(board.stkChessPieceEated);
            ucChessPieceEated2.LoadChessPieces(board.stkChessPieceEated);

            if (board.OwnSide == eChessSide.White)
            {
                ucCountDownTimer2.StartTimer();
            }
            else
            {
                ucCountDownTimer1.StartTimer();
            }
            this.ResumeLayout();
        }
Exemplo n.º 6
0
 public UI(int size = 0)
 {
     m_GameDifficulty = eGameDifficulty.Easy;
     m_CardsData      = new List <char>(size);
     m_PcPlayerLogic  = null;
 }
Exemplo n.º 7
0
        public static ChessMove MakeAComputerMove(ChessState[,] arrState, eChessSide side, Dictionary <string, int> arrPosition, eGameDifficulty difficult, eChessSide ownside)
        {
            _myBestMove  = null;
            _myBestScore = _lowestScore;

            if (difficult == eGameDifficulty.Hard)
            {
                _maxDepth = 5;
            }
            else if (difficult == eGameDifficulty.Normal)
            {
                _maxDepth = 4;
            }
            else
            {
                _maxDepth = 3;
            }

            _mySide = side;
            _opSide = eChessSide.Black;
            if (_mySide == eChessSide.Black)
            {
                _opSide = eChessSide.White;
            }
            _ownSide = ownside;

            if (FindAllPosibleMoves(arrState, _mySide, _ownSide).Count + FindAllPosibleMoves(arrState, _opSide, _ownSide).Count < 30)
            {
                _maxDepth = 5;
            }

            ChessState[,] NewState = new ChessState[10, 10];
            for (int i = 0; i <= 9; i++)
            {
                for (int j = 0; j <= 9; j++)
                {
                    NewState[i, j] = new ChessState(arrState[i, j].Type, arrState[i, j].Side, arrState[i, j].Moves);
                }
            }

            AlphaBeta(NewState, arrPosition, _maxDepth, _mySide, _lowestScore, -_lowestScore);

            /*
             * PredictMove(NewState, _myBestMove);
             * if (Checked(NewState, _mySide) == false)
             *  return _myBestMove;
             *
             * return RandomMove(State,side);*/
            return(_myBestMove);
        }