Example #1
0
        public void IsImmediateWinSuccessForPlayerX()
        {
            int  score  = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 0);
            bool result = MoveScoreConverter.IsImmediateWin(Occupied.PlayerX, score);

            Assert.IsTrue(result);
        }
Example #2
0
        public void WinForPlayerYIsNotWinForPlayerX()
        {
            int  score  = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 0);
            bool result = MoveScoreConverter.IsImmediateWin(Occupied.PlayerX, score);

            Assert.IsFalse(result);
        }
Example #3
0
        public void DescribeYWinner()
        {
            int    score       = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 2);
            string description = MoveScoreConverter.DescribeScore(score);

            Assert.AreEqual("Win by Y in 2 moves", description);
        }
Example #4
0
        /// <summary>
        /// public wrapper for recursion
        /// try each possible move, find the one with the best score
        /// </summary>
        /// <param name="lookahead">how far to look ahead</param>
        /// <param name="playerX">is this for player x</param>
        /// <returns>The data on the best move location and score</returns>
        public MinimaxResult DoMinimax(int lookahead, bool playerX)
        {
            // set up inital state
            DateTime startTime = DateTime.Now;

            if (lookahead < 1)
            {
                throw new Exception("Invalid lookahead of " + lookahead);
            }

            this.debugDataItems.Clear();

            Occupied player = playerX.ToPlayer();
            int      alpha  = MoveScoreConverter.ConvertWin(player.Opponent(), 0);
            int      beta   = MoveScoreConverter.ConvertWin(player, 0);

            MinimaxResult bestMove = this.ScoreBoard(lookahead, this.ActualBoard, playerX, alpha, beta);

            if (bestMove.Move != Location.Null)
            {
                GoodMoves.AddGoodMove(0, bestMove.Move);
            }

            DateTime endTime = DateTime.Now;

            this.MoveTime = endTime - startTime;

            return(bestMove);
        }
Example #5
0
        public void WinIsBetterForPlayerY()
        {
            int winScoreX = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 2);
            int winScoreY = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 2);

            Assert.IsTrue(MoveScoreConverter.IsBetterFor(winScoreY, winScoreX, false));
            Assert.IsFalse(MoveScoreConverter.IsBetterFor(winScoreY, winScoreX, true));
        }
Example #6
0
        public void NearWinForPlayerYIsLessNegative()
        {
            int playerYWin    = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 1);
            int playerYFarWin = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 2);

            Assert.Less(playerYWin, playerYFarWin);
            Assert.Less(playerYFarWin, 0);
            Assert.Less(playerYWin, 0);
        }
Example #7
0
        public void NearWinForPlayerXIsGreater()
        {
            int playerXWin    = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 1);
            int playerXFarWin = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 2);

            Assert.Greater(playerXWin, playerXFarWin);
            Assert.Greater(playerXFarWin, 0);
            Assert.Greater(playerXWin, 0);
        }
Example #8
0
        public void WinForPlayerXIsGreaterThanWinForPlayerY()
        {
            int playerXWin = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 0);
            int playerYWin = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 0);

            Assert.Greater(playerXWin, playerYWin);
            Assert.Greater(playerXWin, 0);
            Assert.Less(playerYWin, 0);
        }
Example #9
0
        public void LaterWinForPLayerXIsNotImmediateWin()
        {
            int  score      = MoveScoreConverter.ConvertWin(Occupied.PlayerX, 1);
            bool resultForX = MoveScoreConverter.IsImmediateWin(Occupied.PlayerX, score);
            bool resultForY = MoveScoreConverter.IsImmediateWin(Occupied.PlayerY, score);

            Assert.IsFalse(resultForX, "X");
            Assert.IsFalse(resultForY, "Y");
        }
Example #10
0
        public MinimaxResult DoMinimax(int depth, bool isComputer)
        {
            // megmondja, hogy ki a jatekos, ha a gep, akkor az isComputerben true van, es akkor a plyaerben xPlayer lesz.
            Occupied player = isComputer.ToPlayer();

            // a gep az alpha
            this.alpha = MoveScoreConverter.ConvertWin(player.Opponent(), 0);
            // ember a beta
            this.beta = MoveScoreConverter.ConvertWin(player, 0);
            // a minimax algoritmus magaban
            MinimaxResult bestMove = this.MiniMaxAlg(depth, isComputer, board);

            if (bestMove.Move != Location.Null)
            {
                // killer heurisztika
                GoodMoves.AddGoodMove(0, bestMove.Move);
            }
            return(bestMove);
        }
Example #11
0
        public int SituationScore()
        {
            int playerXScore = this.PlayerScore(true);

            if (playerXScore == 0)
            {
                // player x wins
                return(MoveScoreConverter.ConvertWin(Occupied.PlayerX, 0));
            }

            if (playerXScore == PathLengthConstants.OffPath)
            {
                // player X loses -> player y wins
                return(MoveScoreConverter.ConvertWin(Occupied.PlayerY, 0));
            }

            // no win yet. score for the situation
            int playerYScore = this.PlayerScore(false);

            return(playerYScore - playerXScore);
        }
Example #12
0
        public void WinnerYIsWinner()
        {
            int score = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 1);

            Assert.AreEqual(Occupied.PlayerY, MoveScoreConverter.Winner(score));
        }