Exemplo n.º 1
0
        private void CheckEndGame()
        {
            //pri detekcii vyhry vyhodi messagebox
            if (GameEngine.GetGameState(gameMap) != GameState.ONGOING)
            {
                string message;
                switch (GameEngine.GetGameState(gameMap))
                {
                case GameState.DRAW:
                    message = "Je remiza.";
                    break;

                case GameState.WIN_PLAYER:
                    message = "Vyhral uzivatel";
                    break;

                case GameState.WIN_COMPUTER:
                    message = "Vyhral computer";
                    break;

                default:
                    message = "Neznama chyba";
                    break;
                }
                ;

                MessageBox.Show(message, "Tic-Tac-Toe-quest");
                isGame = false;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Vypocet skore sa odvija od finalneho stavu hry a urovne v ktorej je dosiahnuty
        /// </summary>
        /// <returns>Skore pre danu cast stromu</returns>
        private int GetScore()
        {
            int myScore = 0;

            //ak si posledny v zozname, vyrataj svoje skore, inak si zober najvyssie skore svojich listov
            if (tree.Count == 0)
            {
                myScore = GameEngine.GetGameState(this.map) == GameState.WIN_COMPUTER ? 10 : GameEngine.GetGameState(this.map) == GameState.WIN_PLAYER ? -10 : 0;
                myScore = myScore * 10 * (9 - level);
            }
            else
            {
                foreach (AItree leaf in tree)
                {
                    if (Math.Abs(leaf.score) > Math.Abs(myScore))
                    {
                        myScore = leaf.score;
                    }
                }
            }
            return(myScore);
        }
Exemplo n.º 3
0
        private void generateMe(int[,] actualMap, Point p, int level)
        {
            this.level    = level;
            this.score    = 0;
            this.position = p;
            this.tree     = new List <AItree>();
            this.map      = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    this.map[i, j] = actualMap[i, j];
                }
            }
            if (GameEngine.GetGameState(this.map) == GameState.ONGOING)
            {
                for (int row = 0; row < 3; row++)
                {
                    for (int column = 0; column < 3; column++)
                    {
                        if (actualMap[row, column] == 0)
                        {
                            int[,] map = new int[3, 3];
                            for (int i = 0; i < 3; i++)
                            {
                                for (int j = 0; j < 3; j++)
                                {
                                    map[i, j] = this.map[i, j];
                                }
                            }

                            map[row, column] = 2 - (level % 2);
                            tree.Add(new AItree(map, new Point(row, column), this.level + 1));
                        }
                    }
                }
            }
            this.score = GetScore();
        }