Exemple #1
0
        /// <summary>
        /// Play new game - User as O
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemFileNewGameSinglePlayerAsO_Click(object sender, System.EventArgs e)
        {
            this.turn = 0;
            movesLeft = BOARD_SIZE;
            win = 0;
            gameType = GameType.UserOVsAgent;
            currentState = new int[BOARD_SIZE] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            GetMove getMove;

            //Agent makes first, need to pull first move.
            if(this.menuItemEditOpponentDPAgent.Checked)
            {
                agentDPX = new Agent.DynamicProgramming(Player.First);
                getMove = agentDPX.getMove;
            }
            else if(this.menuItemEditOpponentMCAgent.Checked)
            {
                agentMCX = new Agent.MonteCarlo(Player.First);
                getMove = agentMCX.getMove;
            }
            else //this menuItem22.Checked
            {
                agentTDX = new Agent.TemporalDifference(Player.First);
                getMove = agentTDX.getMove;
            }
            currentState[getMove(currentState)] = 1;
            turn = 1;
            //User.User userO = new User.User();
            this.pictureBox.Invalidate();
        }
Exemple #2
0
        /// <summary>
        /// Play new game - User as X
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemFileNewGameSinglePlayerAsX_Click(object sender, System.EventArgs e)
        {
            this.turn = 0;
            movesLeft = BOARD_SIZE;
            win = 0;
            gameType = GameType.UserXVsAgent;
            currentState = new int[BOARD_SIZE] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //User.User userX = new User.User();

            //Player makes first move, so just need to initialize agents
            if(this.menuItemEditOpponentDPAgent.Checked)
            {
                agentDPO = new Agent.DynamicProgramming(Player.Second);
            }
            else if(this.menuItemEditOpponentMCAgent.Checked)
            {
                agentMCO = new Agent.MonteCarlo(Player.Second);
            }
            else //this menuItem22.Checked
            {
                agentTDO = new Agent.TemporalDifference(Player.Second);
            }

            this.pictureBox.Invalidate();
        }
Exemple #3
0
        /// <summary>
        /// Play new game - Agent vs. Agent Simulation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemFileNewGameSimulation_Click(object sender, System.EventArgs e)
        {
            ReadCount();

            this.progressBar.Maximum = count;
            this.progressBar.Step = 1;
            this.progressBar.Show();
            this.progressBar.Value = 0;

            this.statusBarPanel.Text = "Running Simulations";
            this.statusBar.Invalidate();

            GetMove getMoveX;
            GetMove getMoveO;
            Update updateX;
            Update updateO;

            #region Agent Declarations
            if (this.menuItemEditOpponentDPAgent.Checked)
            {
                agentDPX = new Agent.DynamicProgramming(Player.First);
                getMoveX = agentDPX.getMove;
                updateX = agentDPX.update;
            }
            else if (this.menuItemEditOpponentMCAgent.Checked)
            {
                agentMCX = new Agent.MonteCarlo(Player.First);
                getMoveX = agentMCX.getMove;
                updateX = agentMCX.update;
            }
            else// (this.menuItemEditOpponentTDAgent.Checked)
            {
                agentTDX = new Agent.TemporalDifference(Player.First);
                getMoveX = agentTDX.getMove;
                updateX = agentTDX.update;
            }

            if (this.menuItemFileNewGameSimulationAgainstMC.Checked)
            {
                agentMCO = new Agent.MonteCarlo(Player.Second);
                getMoveO = agentMCO.getMove;
                updateO = agentMCO.update;
            }
            else if (this.menuItemFileNewGameSimulationAgainstTD.Checked)
            {
                agentTDO = new Agent.TemporalDifference(Player.Second);
                getMoveO = agentTDO.getMove;
                updateO = agentTDO.update;
            }
            else//(this.menuItem33.Checked || default)
            {
                agentDPO = new Agent.DynamicProgramming(Player.Second);
                getMoveO = agentDPO.getMove;
                updateO = agentDPO.update;
            }
            #endregion

            for (int j = 0; j < count; j++)
            {
                if (agentMCO != null)
                    agentMCO.Reset();

                if (agentMCX != null)
                    agentMCX.Reset();

                this.progressBar.Increment(this.progressBar.Step);
                this.pictureBox.Invalidate();

                movesLeft = BOARD_SIZE;
                win = 0;
                gameType = GameType.AgentVsAgent;
                currentState = new int[BOARD_SIZE] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                bool turnBase = true;

                #region Play until win
                while (this.win == 0)
                {
                    if (turnBase)
                    {
                        turnBase = false;
                        MakeAgentVsAgentMove(getMoveX, Player.First);
                    }
                    else
                    {
                        turnBase = true;
                        MakeAgentVsAgentMove(getMoveO,Player.Second);
                    }
                }
                #endregion

                #region update results to agent
                if (winner == 1)//X won
                {
                    updateX(GameResult.Win, currentState, gameType);
                    updateO(GameResult.Lost, previousState, gameType);
                }
                else if (winner == 2)//O won
                {
                    updateX(GameResult.Lost, previousState, gameType);
                    updateO(GameResult.Win, currentState, gameType);
                }
                else //Cat's game
                {
                    if (turn == 0)
                    {
                        updateX(GameResult.Tie, previousState, gameType);
                        updateO(GameResult.Tie, currentState, gameType);
                    }
                    else //turn ==1
                    {
                        updateX(GameResult.Tie, currentState, gameType);
                        updateO(GameResult.Tie, currentState, gameType);
                    }
                }
                #endregion

                this.pictureBox.Invalidate();
            }

            this.statusBarPanel.Text = "Done";
            this.progressBar.Hide();
            this.statusBar.Invalidate();
        }