private void SelectMove(int step)
        {
            game = new UTTT(gameField);

            String[] moves = gameHistory.Split(';');

            File.Delete("Game.ai");
            for (int move = 5; move < 5 + step; ++move)
            {
                game.SetMark(moves[move], true);
            }
        }
        private void Match_Load(object sender, EventArgs e)
        {
            game         = new UTTT(gameField);
            current_step = 0;

            String[] moves = gameHistory.Split(';');
            roomName.Text = "Playing:\r\n\r\n" + moves[1] + " - " + moves[2];

            bot = new Bot(BotLevel.EASY, Player.O);

            analysis.Checked   = false;
            diff.SelectedIndex = 0;
        }
Exemple #3
0
        public UTTT Clone()
        {
            UTTT game = new UTTT(field);

            for (int row = 0; row < 3; ++row)
            {
                for (int column = 0; column < 3; ++column)
                {
                    game.board[row, column] = board[row, column].Clone();
                }
            }

            game.lastBig   = lastBig;
            game.lastSmall = lastSmall;
            game.areas     = (bool[, ])areas.Clone();

            return(game);
        }
Exemple #4
0
        private void botGameInit(BotLevel level)
        {
            botGameCopy      = null;
            botGameIsPlaying = true;
            if (!firstMove.Checked)
            {
                playerColor = Player.O;
                botColor    = Player.X;
            }

            botGame = new UTTT(botField);
            bot     = new Bot(level, botColor);

            if (!firstMove.Checked)
            {
                botGame.SetMark(bot.NextMove(botGame.gameStateToString()));
            }

            analysis.Checked   = false;
            diff.SelectedIndex = 0;
        }
Exemple #5
0
        private void botField_MouseClick(object sender, MouseEventArgs e)
        {
            if (botGameIsPlaying)
            {
                botGameCopy = botGame.Clone();

                if (botGame.SetMark(new Point(e.X, e.Y), playerColor) == "ERROR")
                {
                    return;
                }

                CheckGameState();



                if (!botGame.GameIsEnded())
                {
                    String gameState = botGame.gameStateToString();
                    String botMove   = bot.NextMove(gameState);
                    Console.WriteLine(botMove);

                    botGame.SetMark(botMove);

                    CheckGameState();

                    if (analysis.Checked && botGameIsPlaying)
                    {
                        botGame.DisableAnalysis();
                        botGame.Draw();
                        String scores = bot.Analysis(botGame.gameStateToString());
                        botGame.EnableAnalysis(scores);
                    }
                }
                botGame.Draw();
            }
        }
Exemple #6
0
 private void Test_Load(object sender, EventArgs e)
 {
     game = new UTTT(field);
 }
Exemple #7
0
 private void UnmakeLastMove()
 {
     botGame     = botGameCopy.Clone();
     botGameCopy = null;
 }
        private void RoomUpdate(object sender, EventArgs e)
        {
            String response = Client.SendMessage("getRoomInfo;" + Client.GetSelectedGame());

            if (response == "gameIsCanceled")
            {
                leave_Click(sender, e);
                MessageBox.Show("Game is canceled");
            }
            String[] tokens = response.Split(';');

            if (response.Split(';').First() == Client.GetLogin())
            {
                leave.Text = "Close room";
            }



            if (response.Contains(";Playing"))
            {
                leave.Text     = "Leave room";
                accept.Enabled = false;

                this.Text = "Playing:    " + tokens[0] + " [" + tokens[1] + "] " + " - " +
                            tokens[2] + " [" + tokens[3] + "] ";

                time.Text = "Time:\r\n\r\n" + tokens[0] + ":  " + ToClockFormat(tokens[4]) +
                            "\r\n" + tokens[2] + ":  " + ToClockFormat(tokens[5]);

                turn.Text = tokens[9] + "'S TURN";

                if (tokens[9] == Client.GetLogin())
                {
                    isMyTurn = true;
                }
                else
                {
                    isMyTurn = false;
                }

                if (tokens[10] == "X")
                {
                    player = Player.X;
                }

                if (tokens[10] == "O")
                {
                    player = Player.O;
                }

                String history = response.Split('{')[1].Split('}').First();

                if (gameHistory != history)
                {
                    gameHistory = history;
                    game        = new UTTT(gameField);
                    String[] moves = history.Split(';');
                    foreach (String move in moves)
                    {
                        game.SetMark(move);
                    }
                }
            }
            else if (response.Contains(";Ended"))
            {
                if (!game.GameIsEnded())
                {
                    game.EndGame();
                }

                if (response.Contains('{'))
                {
                    String history = response.Split('{')[1].Split('}').First();

                    if (gameHistory != history)
                    {
                        gameHistory = history;
                        game        = new UTTT(gameField);
                        String[] moves = history.Split(';');
                        foreach (String move in moves)
                        {
                            game.SetMark(move);
                        }
                    }
                }
            }
            else if (response.Contains(";Created"))
            {
                accept.Enabled = true;
                turn.Text      = "";
                this.Text      = Client.GetSelectedGame() + "'s room";
                time.Text      = "Time: " + (int.Parse(tokens[2]) / 60).ToString() + " minutes.";
            }


            if (response.Split(';').First() == Client.GetLogin())
            {
                accept.Enabled = false;
            }

            chat.Text = tokens.Last();
        }
 private void Game_Load(object sender, EventArgs e)
 {
     game = new UTTT(gameField);
     Update_Tick(sender, e);
     GameUpdate();
 }