private float bfs_bestConsequence(GameState gs, int depth)
        {
            if (depth == 0)
                return evaluate(gs);
            else
            {
                float bestEvaluation = -1;
                List<Action> actions = gs.availableActions();
                foreach (Action a in actions)
                {
                    float currentEvaluation = bfs_bestConsequence(executeOrDoNothing(a, gs), depth - 1);
                    if (bestEvaluation < currentEvaluation)
                        bestEvaluation = currentEvaluation;
                }
                return bestEvaluation;
            }

        }
        public Action bfs_findbest(GameState gs, int depth)
        {

            Debug.Assert(depth > 0);
            float bestEvaluation = -1;

            List<Pair> initialActions = new List<Pair>();
            foreach (Action a in gs.availableActions())
            {
                Pair actionPair = new Pair();
                actionPair.initialAction = a;
                actionPair.resultState = executeOrDoNothing(a,gs);
                initialActions.Add(actionPair);
            }
            Action result = bfs_bestConsequenceReduced(initialActions, depth - 1);
            //Console.WriteLine("My best action was: " + result.ToString() + " with a score of " + bestEvaluation);
            return result;
        }
Exemple #3
0
        public Action bfs_findbest(GameState gs, int depth)
        {
            Debug.Assert(depth > 0);
            float bestEvaluation = -1;

            List <Pair> initialActions = new List <Pair>();

            foreach (Action a in gs.availableActions())
            {
                Pair actionPair = new Pair();
                actionPair.initialAction = a;
                actionPair.resultState   = executeOrDoNothing(a, gs);
                initialActions.Add(actionPair);
            }
            Action result = bfs_bestConsequenceReduced(initialActions, depth - 1);

            //Console.WriteLine("My best action was: " + result.ToString() + " with a score of " + bestEvaluation);
            return(result);
        }
Exemple #4
0
        public Action bfs_findbest_old(GameState gs, int depth)
        {
            Debug.Assert(depth > 0);
            float  bestEvaluation = -1;
            Action bestAction     = null;

            foreach (Action a in gs.availableActions())
            {
                float currentEvaluation = bfs_bestConsequence(executeOrDoNothing(a, gs), depth - 1);
                if (bestEvaluation < currentEvaluation)
                {
                    bestEvaluation = currentEvaluation;
                    bestAction     = a;
                }
            }

            // Console.WriteLine("My best action was: " + bestAction.ToString() + " with a score of " + bestEvaluation);
            return(bestAction);
        }
Exemple #5
0
 private float bfs_bestConsequence(GameState gs, int depth)
 {
     if (depth == 0)
     {
         return(evaluate(gs));
     }
     else
     {
         float         bestEvaluation = -1;
         List <Action> actions        = gs.availableActions();
         foreach (Action a in actions)
         {
             float currentEvaluation = bfs_bestConsequence(executeOrDoNothing(a, gs), depth - 1);
             if (bestEvaluation < currentEvaluation)
             {
                 bestEvaluation = currentEvaluation;
             }
         }
         return(bestEvaluation);
     }
 }
        public Action bfs_findbest_old(GameState gs, int depth)
        {

            Debug.Assert(depth > 0);
            float bestEvaluation = -1;
            Action bestAction = null;

            foreach (Action a in gs.availableActions())
            {
                float currentEvaluation = bfs_bestConsequence(executeOrDoNothing(a, gs), depth - 1);
                if (bestEvaluation < currentEvaluation)
                {
                    bestEvaluation = currentEvaluation;
                    bestAction = a;
                }

            }

           // Console.WriteLine("My best action was: " + bestAction.ToString() + " with a score of " + bestEvaluation);
            return bestAction;
        }
Exemple #7
0
        public void runAction()
        {
            Action a;

            if (gs.currentPlayer().isAI)
            {
                a = ev.bfs_findbest(gs, 9);
            }
            else
            {
                ActionChooser foo = new ActionChooser(gs.availableActions());
                foo.ShowDialog();
                a = foo.selection;
            }
            lastAction = a;
            gs         = a.execute(gs);

            if (gs.hasEpidemic)
            {
                gs.hasEpidemic = false;
                MessageBox.Show("Epidemic Occured!");
            }

            //throw up some GUI
            if (gs.hasLost())
            {
                MessageBox.Show("You Lost");
                Application.Exit();
            }

            if (gs.hasWon())
            {
                MessageBox.Show("You Won");
                Application.Exit();
            }
        }
 public void TestMakeStationAction()
 {
     gs = new GameState(newyork, map, 2, 1);
     Player p1 = gs.currentPlayer();
     Player p1wCard = p1.addCard(newyork);
     gs = gs.adjustPlayer(p1wCard);
     gs = gs.setTurnAction(new DoNothingTurnAction());
     SearchEvaluate likesStations = new LikesStations(1);
     List<Action> foo = gs.availableActions();
     Action action = likesStations.bfs_findbest(gs, 1);
     GameState newGS = action.execute(gs);
     Assert.AreEqual(0, newGS.players[1].cards.Count);
     // Assert.AreEqual(0, newGS.players[1].cards.Count);
     Assert.AreEqual(true, newGS.map.hasStation(newyork));
 }
        public void TestTrade()
        {
            gs = new GameState(newyork, map, 2, 1);
            Player p1 = gs.currentPlayer();
            Player p1wCard = p1.addCard(newyork);
            gs = gs.adjustPlayer(p1wCard);
            gs = gs.setTurnAction(new DoNothingTurnAction());
            SearchEvaluate likesCards = new LikesCards(1);
            List<Action> foo = gs.availableActions();
            Action action = likesCards.bfs_findbest(gs, 1);
            GameState newGS = action.execute(gs);
            Assert.AreEqual(0, newGS.players[0].cards.Count);
            Assert.AreEqual(1, newGS.players[1].cards.Count);

            gs = new GameState(newyork, map, 2, 1);
            p1 = gs.currentPlayer();
            p1wCard = p1.addCard(newark);
            gs = gs.adjustPlayer(p1wCard);
            gs = gs.setTurnAction(new DoNothingTurnAction());
            action = likesCards.bfs_findbest(gs, 5);
            newGS = action.execute(gs);
            Assert.AreEqual(1, newGS.players[0].cards.Count);
            Assert.AreEqual(0, newGS.players[1].cards.Count);
            newGS = doSteps(newGS, likesCards, 4, 5);
            Assert.AreEqual(0, newGS.players[0].cards.Count);
            Assert.AreEqual(0, newGS.players[1].cards.Count);

        }
 public void TestTurnAction()
 {
     Deck<City> infect = new Deck<City>(map.allCities, false);
     Deck<City> playerDeck = new Deck<City>(map.allCities, false);
     gs = new GameState(newyork, map, 1, 1, infect, playerDeck);
     GameState gs2 = gs.availableActions()[0].execute(gs);
     Assert.AreEqual(1, gs2.availableActions().Count);
     GameState gs3 = gs2.availableActions()[0].execute(gs2);
     Assert.AreEqual(12, infect.drawDeck.Count);
     Assert.AreEqual(0, infect.discardDeck.Count);
     Assert.AreEqual(10, gs3.infectionDeck.drawDeck.Count);
     Assert.AreEqual(2, gs3.infectionDeck.discardDeck.Count);
     Assert.AreEqual(1, gs3.map.diseaseLevel(newark, DiseaseColor.BLUE));
     Assert.AreEqual(1, gs3.map.diseaseLevel(newyork, DiseaseColor.BLUE));
 }
Exemple #11
0
        public void currentPlayerTest()
        {
            //3 players
            gs = new GameState(atlanta, map, 3, 1);
            gs = gs.setTurnAction(new DoNothingTurnAction());

            Player startPlayer = gs.currentPlayer();
            Action someAction = gs.availableActions()[0];
            GameState newGS = someAction.execute(gs);
            Assert.AreEqual(1, newGS.availableActions().Count);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreNotEqual(startPlayer.playernum, newGS.currentPlayer().playernum);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreEqual(1, newGS.availableActions().Count);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);

            Assert.AreNotEqual(startPlayer.playernum, newGS.currentPlayer().playernum);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreEqual(1, newGS.availableActions().Count);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreEqual(startPlayer.playernum, newGS.currentPlayer().playernum);

            //2 moves per player
            gs = new GameState(atlanta, map, 2, 2);
            gs = gs.setTurnAction(new DoNothingTurnAction());
            startPlayer = gs.currentPlayer();
            someAction = gs.availableActions()[0];
            newGS = someAction.execute(gs);
            Assert.AreEqual(startPlayer.playernum, newGS.currentPlayer().playernum);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreEqual(1, newGS.availableActions().Count);
            someAction = newGS.availableActions()[0];
            newGS = someAction.execute(newGS);
            Assert.AreNotEqual(startPlayer.playernum, newGS.currentPlayer().playernum);

        }