コード例 #1
0
 public override float evaluate(GameState gs)
 {
     if (gs.currentPlayer().position == city)
         return 1;
     else
         return 0;
 }
コード例 #2
0
ファイル: TradeAction.cs プロジェクト: grigorescu/pandemic
 public static List<TradeAction> getTrades(GameState gs)
 {
     List<TradeAction> result = new List<TradeAction>();
     City card = gs.currentPlayer().position;
     List<Player> partners = new List<Player>();
     Player trader = null;
     foreach(Player p in gs.players)
     {
         if (p.position == card)
         {
             if (p.cards.Contains(card))
             {
                 trader = p;
             }
             else
             {
                 partners.Add(p);
             }
         }
     }
     if(trader == null) return result;
     foreach(Player p in partners)
     {
         result.Add(new TradeAction(trader, p, card));
     }
     return result;
 }
コード例 #3
0
ファイル: TurnAction.cs プロジェクト: grigorescu/pandemic
        public override GameState execute(GameState gs)
        {
            //does stuff that happens between two turns (after actions)
            
            GameState newGS  = gs.drawPlayerCards(gs.currentPlayer());
            int numInfectionCardsToDraw=0;
            Map m = newGS.map;
            //draw x infection cards
            if(m.infectionRate>=0 && m.infectionRate<3)
            {
                numInfectionCardsToDraw = 2;
            }
            else if (m.infectionRate >= 3 && m.infectionRate < 5)
            {
                numInfectionCardsToDraw = 3;
            }
            else if(m.infectionRate >=5 && m.infectionRate<7)
            {
                numInfectionCardsToDraw = 4;
            }

            newGS = newGS.drawInfectionCards(numInfectionCardsToDraw);
            newGS.advancePlayer();
            


            return newGS;
        }
コード例 #4
0
ファイル: MoveAction.cs プロジェクト: grigorescu/pandemic
 public override GameState execute(GameState gs)
 {
     //Debug.Assert(debug_gs == null || debug_gs == gs, "Action used on an unintended gamestate");
     Player movedPlayer = new Player(dest, gs.currentPlayer());
     GameState result = gs.adjustPlayer(movedPlayer);
     result.advanceMove();
     return result;
 }
コード例 #5
0
ファイル: GameStateTest.cs プロジェクト: grigorescu/pandemic
 public void initialize()
 {
     map = new Map();
     atlanta = map.addCity("Atlanta", DiseaseColor.BLUE);
     newyork = map.addCity("NewYork", DiseaseColor.BLUE);
     City.makeAdjacent(atlanta, newyork);
     gs = new GameState(atlanta, map);
 }
コード例 #6
0
 public override GameState execute(GameState current)
 {
     Player newPlayer = new Player(card, player);
     newPlayer = newPlayer.removeCard(card);
     GameState g = current.adjustPlayer(newPlayer);
     g.advanceMove();
     g = g.recalcBestCardHolder(g, newPlayer, card.color);
     return g;
 }
コード例 #7
0
        public override GameState execute(GameState gs)
        {
            
            gs = new GameState(gs, gs.map);
            gs.advancePlayer();


            return gs;
        }
コード例 #8
0
ファイル: SearchEvaluate.cs プロジェクト: grigorescu/pandemic
 public GameState executeOrDoNothing(Action action, GameState gs)
 {
     if (action.isTurnAction())
     {
         return turnAction().execute(gs);
     }
     else
     {
         return action.execute(gs);
     }
 }
コード例 #9
0
ファイル: GameState.cs プロジェクト: grigorescu/pandemic
 public GameState adjustPlayer(Player p)
 {
     GameState result = new GameState(this);
     result.players = new Player[numPlayers];
     for (int i = 0; i < numPlayers; i++)
     {
         result.players[i] = players[i];
     }
     Debug.Assert(p.playernum < numPlayers);
     result.players[p.playernum] = p;
     return result;
 }
コード例 #10
0
ファイル: TradeAction.cs プロジェクト: grigorescu/pandemic
       public override GameState execute(GameState gs)
       {
           Player newFrom = from.removeCard(card);
           Player newTo = to.addCard(card);
           gs = gs.adjustPlayer(newFrom);
           gs = gs.recalcBestCardHolder(gs, newFrom, card.color);
           gs = gs.adjustPlayer(newTo);
           gs = gs.recalcForAddCard(newTo, card);
 
           gs.advanceMove();
           return gs;
       }
コード例 #11
0
        public override GameState execute(GameState current)
        {
            Debug.Assert(debug_gs == null || debug_gs == current, "Action used on an unintended gamestate");

            Map newMap = current.map.addStation(position);
            GameState g = new GameState(current, newMap);
            player = player.removeCard(position);
            g.players[g.currentPlayerNum] = player;
            g.advanceMove();
            g = g.recalcBestCardHolder(g, player, position.color);
            return g;
        }
コード例 #12
0
ファイル: HatesDisease.cs プロジェクト: grigorescu/pandemic
 public static int getTotalDisease(GameState gs)
 {
     int totalDisease = 0;
     foreach (City c in gs.map.allCities)
     {
         totalDisease += gs.map.diseaseLevel(c, DiseaseColor.BLACK);
         totalDisease += gs.map.diseaseLevel(c, DiseaseColor.BLUE);
         totalDisease += gs.map.diseaseLevel(c, DiseaseColor.YELLOW);
         totalDisease += gs.map.diseaseLevel(c, DiseaseColor.ORANGE);
     }
     return totalDisease;
 }
コード例 #13
0
ファイル: ActionTests.cs プロジェクト: grigorescu/pandemic
        public void moveExecuteTest()
        {
            City atlanta = new City("Atlanta", DiseaseColor.BLUE, 0);
            City newyork = new City("NewYork", DiseaseColor.BLUE, 1);
            City.makeAdjacent(atlanta, newyork);
            GameState gs = new GameState(atlanta, null);
            MoveAction action = new MoveAction(newyork);
            GameState newGs = action.execute(gs);
            Assert.AreEqual(newyork, newGs.currentPlayer().position);
            Assert.AreEqual(atlanta, gs.currentPlayer().position);

        }
コード例 #14
0
            public override float evaluate(GameState gs)
            {
                float f = 0;
                foreach (City c in gs.map.allCities)
                {
                    if (gs.map.hasStation(c))
                    {
                        f++;
                    }
                }

                return f / 100;
            }
コード例 #15
0
        public static List<CureDiseaseAction> getCureActions(GameState g)
        {
            List<CureDiseaseAction> result = new List<CureDiseaseAction>();
            if(g.map.hasStation(g.currentPlayer().position)) {
                foreach(DiseaseColor c in g.currentPlayer().hasCardsToCure())
                {
                    if (g.curesFound[(int) c]) continue;

                    result.Add(new CureDiseaseAction(c));
                }
            }
            return result;
        }
コード例 #16
0
ファイル: GameState.cs プロジェクト: grigorescu/pandemic
 private GameState(GameState gs)
 {
     map = gs.map;
     players = gs.players;
     currentPlayerNum = gs.currentPlayerNum;
     numPlayers = gs.numPlayers;
     numMoves = gs.numMoves;
     cpMovesUsed = gs.cpMovesUsed;
     infectionDeck = gs.infectionDeck;
     playerDeck = gs.playerDeck;
     turnAction = gs.turnAction;
     curesFound = gs.curesFound;
     bestCardHolder  = gs.bestCardHolder;
     hasEpidemic = gs.hasEpidemic;
 }
コード例 #17
0
ファイル: outbreakHater.cs プロジェクト: grigorescu/pandemic
        public static float evalGame(GameState gs)
        {
            //check the number of nearly outbroken cities
            float onverge = gs.map.aboutToOutbreak.Count();
            float cures = gs.numCures();
            int totalDisease = gs.map.numInfectionsInCities;
            float lotsOfCardsBonus = 0;

            //fix plz
            
            lotsOfCardsBonus /= gs.players.Count();


            return 0.5f - (onverge / 20) + (cures / 8) + (float)totalDisease / 100 + lotsOfCardsBonus/8;
        }
コード例 #18
0
ファイル: TurnActionTest.cs プロジェクト: grigorescu/pandemic
 public void epidemicDrawTest()
 {
     Map map = new Map();
     City atl = map.addCity("Atlanta", DiseaseColor.BLUE);
     City ny = map.addCity("New York", DiseaseColor.BLUE);
     City.makeAdjacent(atl, ny);
     Deck<City> playerDeck = new Deck<City>(map.allCities, false, true);
     int infectRate;
     GameState gs = new GameState(atl, map, 1, 4, new Deck<City>(map.allCities), playerDeck);
     infectRate = gs.map.infectionRate;
     playerDeck.epidemicCards.Add(1);
     GameState newGS = new TurnAction().execute(gs);
     Assert.IsTrue(newGS.map.diseaseLevel(atl, DiseaseColor.BLUE) == 3 || newGS.map.diseaseLevel(ny, DiseaseColor.BLUE) == 3);
     Assert.AreEqual(infectRate + 1, newGS.map.infectionRate);
 }
コード例 #19
0
ファイル: TurnActionTest.cs プロジェクト: grigorescu/pandemic
 public void epidemicTest()
 {
     Map map = new Map();
     City atl = map.addCity("Atlanta", DiseaseColor.BLUE);
     City ny = map.addCity("New York", DiseaseColor.BLUE);
     City.makeAdjacent(atl,ny);
     Deck<City> playerDeck = new Deck<City>(map.allCities);
     int infectRate;
     GameState gs = new GameState(atl, map, 1, 4, new Deck<City>(map.allCities), playerDeck);
     infectRate = gs.map.infectionRate;
     gs.epidemicCard();
     
     Assert.IsTrue(gs.map.diseaseLevel(atl, DiseaseColor.BLUE) == 3 || gs.map.diseaseLevel(ny, DiseaseColor.BLUE) == 3);
     Assert.AreEqual(infectRate + 1, gs.map.infectionRate);
 }
コード例 #20
0
ファイル: SearchEvaluate.cs プロジェクト: grigorescu/pandemic
        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;
        }
コード例 #21
0
ファイル: SearchEvaluate.cs プロジェクト: grigorescu/pandemic
        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;
            }

        }
コード例 #22
0
        public override GameState execute(GameState gs)
        {
            Player player = gs.currentPlayer();
            int cardsRemoved = 0;

            foreach (City card in player.cards)
            {
                if (cardsRemoved == 5 || (cardsRemoved == 4 && gs.currentPlayer().type == Player.Type.SCIENTIST)) break;
                if (color == card.color)
                {
                    player = player.removeCard(card);
                    cardsRemoved++;
                }
            }
            GameState result = gs.cureDisease(color);
            result = result.adjustPlayer(player);
            result.advanceMove();
            result = result.recalcBestCardHolder(result, gs.currentPlayer(), color);
            return result;

        }
コード例 #23
0
ファイル: SearchEvaluate.cs プロジェクト: grigorescu/pandemic
        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;
        }
コード例 #24
0
ファイル: GameEngine.cs プロジェクト: grigorescu/pandemic
        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();
            }


        }
コード例 #25
0
ファイル: GameEngine.cs プロジェクト: grigorescu/pandemic
        public GameEngine(Player.Type hType, int difficultyLevel, Boolean allAI)
        {

            //initialize infection and player decks and map
            Map map = initializeCities();
            Deck<City> ideck = initializeInfectionDeck(map);
            //initialize player deck

            gs = new GameState(atlanta, map, 4, 4, ideck, initializePlayerDeck(map));
            gs.map = initializeBoard(map);
            if (!allAI)
            {
                gs.players[0].isAI = false;
            }

            foreach (Player p in gs.players)
            {
                gs = gs.drawPlayerCards(p, 5);
                List<City> drawn = gs.playerDeck.mostRecent(5);
                p.cards.AddRange(drawn);
                gs = gs.adjustPlayer(p);
            }


            List<int> cardLocations = makeEpidemicCards(gs.playerDeck.drawDeck.Count, difficultyLevel);

            for (int i = 0; i < cardLocations.Count; i++)
            {
                cardLocations[i] = cardLocations[i] + gs.playerDeck.cardWeAreOn + 1;
            }

            gs.playerDeck.epidemicCards = cardLocations;
            //ev = new HatesDisease(100);
            ev = new outbreakHater(true);

        }
コード例 #26
0
ファイル: outbreakHater.cs プロジェクト: grigorescu/pandemic
 public override float evaluate(GameState gs)
 {
     return evalGame(gs);
 }
コード例 #27
0
ファイル: CureCityAction.cs プロジェクト: grigorescu/pandemic
 public override GameState execute(GameState current)
 {
     Debug.Assert(debug_gs == null || debug_gs == current, "Action used on an unintended gamestate");
     Map newMap = current.map.removeDisease(position, color);
     return new GameState(current, newMap);
 }
コード例 #28
0
ファイル: ActionTests.cs プロジェクト: grigorescu/pandemic
        public void cureExecuteTest()
        {
            Map map = new Map();
            City atlanta = map.addCity("Atlanta", DiseaseColor.BLUE);
            City newyork = map.addCity("NewYork", DiseaseColor.BLUE);
            City.makeAdjacent(atlanta, newyork);
            map = map.addDisease(atlanta);
            GameState gs = new GameState(atlanta, map);
            CureCityAction action = new CureCityAction(atlanta, DiseaseColor.BLUE);
            GameState newGs = action.execute(gs);
            Assert.AreEqual(1, gs.map.diseaseLevel(atlanta, DiseaseColor.BLUE));
            Assert.AreEqual(atlanta, newGs.currentPlayer().position);
            Assert.AreEqual(0, newGs.map.diseaseLevel(atlanta, DiseaseColor.BLUE));

        }
コード例 #29
0
 public override float evaluate(GameState gs)
 {
     return (float)gs.numCures() / 4;
 }
コード例 #30
0
 public GameState doSteps(GameState initial, SearchEvaluate eval, int steps, int depth)
 {
     GameState current = initial;
     for (int i = 0; i < steps; i++)
     {
         Action move = eval.bfs_findbest(current, depth);
         current = move.execute(current);
     }
     return current;
 }