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; }
public override float evaluate(GameState gs) { if (gs.currentPlayer().position == city) return 1; else return 0; }
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); }
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; }
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); }
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; }
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; }
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); }
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); }
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); }
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; }
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); }
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 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 update(GameState gs) { Map map = gs.map; //remove labels on map (old) for (int i = 0; i < toRemove.Count; i++) { this.Controls.Remove((Control)toRemove[i]); } toRemove.Clear(); //update disease cubes and research station on cities and player postion int curOffsetY; foreach (City currentCity in map.allCities) { curOffsetY = 1; createDiseaseLabels(currentCity, gs); if (map.hasStation(currentCity)) { makeLabel("STATION", currentCity, 0, curOffsetY, Color.Black, Color.PaleVioletRed); curOffsetY++; } createPlayersLabels(currentCity, gs, curOffsetY); } //current player + last action HUD info makePlayer(gs.currentPlayer().ToString(), .952f, .107f, 0, 0, 2); if (ge.lastAction != null) { //String lastAct = gs.currentPlayer().ToString() + ge.lastAction.ToString(); makeLabel(("Player " + gs.currentPlayer().ToString() + ": " + ge.lastAction.ToString()), .848f, .450f, Color.Green, Color.LightGray, 9); } this.currPlayerInfo.Text = gs.currentPlayer().ToLongDescr(); //other players cards String otherHandstxt = null; int n = 0; foreach (Player p in gs.players) { if (p.playernum != gs.currentPlayerNum) { n = p.playernum + 1; otherHandstxt += "PLAYER " + n + " hand: \n"; foreach (City c in p.cards) { otherHandstxt += c.name + "\n"; } } } this.otherHands.Text = otherHandstxt; //outbreak counter switch (gs.map.outbreakCount) { case 0: makeCounter(false, .023f, .564f); break; case 1: makeCounter(false, .048f, .619f); break; case 2: makeCounter(false, .019f, .658f); break; case 3: makeCounter(false, .048f, .711f); break; case 4: makeCounter(false, .022f, .760f); break; case 5: makeCounter(false, .047f, .790f); break; case 6: makeCounter(false, .019f, .850f); break; case 7: makeCounter(false, .049f, .890f); break; case 8: makeCounter(false, .020f, .931f); break; } //infection counter switch (gs.map.infectionRate) { case 0: makeCounter(true, .505f, .190f); break; case 1: makeCounter(true, .542f, .200f); break; case 2: makeCounter(true, .578f, .214f); break; case 3: makeCounter(true, .616f, .224f); break; case 4: makeCounter(true, .652f, .220f); break; case 5: makeCounter(true, .686f, .210f); break; case 6: makeCounter(true, .723f, .195f); break; } //infection discard deck this.discardInfection.Text = gs.infectionDeck.mostRecent(1)[0].name; //cards left in the player deck makeLabel((gs.playerDeck.drawDeck.Count.ToString() + " cards left"), .537f, .737f, Color.White, Color.Navy); //disease irradicated }
public void TestmedSmartAi() { City newyork = map.addCity("ny", DiseaseColor.BLUE); City atl = map.addCity("atl", DiseaseColor.BLUE); City washington = map.addCity("washington", DiseaseColor.BLUE); City chicago = map.addCity("chicago", DiseaseColor.BLUE); City.makeAdjacent(newyork, atl); City.makeAdjacent(atl, washington); City.makeAdjacent(washington, chicago); //ny-->atl-->washington-->chicago map = map.addDisease(newyork, 3); gs = new GameState(newyork, map, 2); Player p1 = gs.currentPlayer(); gs = gs.adjustPlayer(p1); gs = gs.setTurnAction(new DoNothingTurnAction()); SearchEvaluate noOutbreaks = new outbreakHater(true); List<Action> foo = new List<Action>(); Action q = new CureCityAction(newyork, newyork.color); GameState cured = q.execute(gs); float eval = outbreakHater.evalGame(cured); Action action = noOutbreaks.bfs_findbest(gs, 1); GameState newGS = action.execute(gs); float eval2 = outbreakHater.evalGame(newGS); Assert.AreEqual(2, newGS.map.diseaseLevel(newyork, newyork.color)); //Assert.AreEqual(1, gs.map.aboutToOutbreak.Count()); //testing adding + removin disease from about to outbreak list newGS.map = newGS.map.addDisease(chicago, 3); Assert.AreEqual(1, gs.map.aboutToOutbreak.Count()); newGS.map = newGS.map.removeDisease(chicago, chicago.color); Assert.AreEqual(1, gs.map.aboutToOutbreak.Count()); newGS.map = newGS.map.removeDisease(chicago, chicago.color); Assert.AreEqual(1, gs.map.aboutToOutbreak.Count()); Assert.AreEqual(0, gs.map.diseaseLevel(chicago, chicago.color)); }
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 update(GameState gs) { Map map = gs.map; //remove labels on map (old) for(int i=0; i<toRemove.Count;i++) { this.Controls.Remove((Control)toRemove[i]); } toRemove.Clear(); //update disease cubes and research station on cities and player postion int curOffsetY; foreach (City currentCity in map.allCities) { curOffsetY = 1; createDiseaseLabels(currentCity, gs); if(map.hasStation(currentCity)) { makeLabel("STATION", currentCity, 0, curOffsetY, Color.Black, Color.PaleVioletRed); curOffsetY++; } createPlayersLabels(currentCity, gs, curOffsetY); } //current player + last action HUD info makePlayer(gs.currentPlayer().ToString(), .952f, .107f, 0, 0, 2); if (ge.lastAction != null) { //String lastAct = gs.currentPlayer().ToString() + ge.lastAction.ToString(); makeLabel(("Player " + gs.currentPlayer().ToString() + ": " + ge.lastAction.ToString()), .848f, .450f, Color.Green, Color.LightGray, 9); } this.currPlayerInfo.Text = gs.currentPlayer().ToLongDescr(); //other players cards String otherHandstxt = null; int n = 0; foreach (Player p in gs.players) { if (p.playernum != gs.currentPlayerNum) { n = p.playernum + 1; otherHandstxt += "PLAYER " + n + " hand: \n"; foreach (City c in p.cards) { otherHandstxt += c.name + "\n"; } } } this.otherHands.Text = otherHandstxt; //outbreak counter switch (gs.map.outbreakCount) { case 0: makeCounter(false, .023f, .564f); break; case 1: makeCounter(false, .048f, .619f); break; case 2: makeCounter(false, .019f, .658f); break; case 3: makeCounter(false, .048f, .711f); break; case 4: makeCounter(false, .022f, .760f); break; case 5: makeCounter(false, .047f, .790f); break; case 6: makeCounter(false, .019f, .850f); break; case 7: makeCounter(false, .049f, .890f); break; case 8: makeCounter(false, .020f, .931f); break; } //infection counter switch (gs.map.infectionRate) { case 0: makeCounter(true, .505f, .190f); break; case 1: makeCounter(true, .542f, .200f); break; case 2: makeCounter(true, .578f, .214f); break; case 3: makeCounter(true, .616f, .224f); break; case 4: makeCounter(true, .652f, .220f); break; case 5: makeCounter(true, .686f, .210f); break; case 6: makeCounter(true, .723f, .195f); break; } //infection discard deck this.discardInfection.Text = gs.infectionDeck.mostRecent(1)[0].name; //cards left in the player deck makeLabel((gs.playerDeck.drawDeck.Count.ToString()+ " cards left"), .537f, .737f, Color.White, Color.Navy); //disease irradicated }
public void TestLoseNoCards() { gs = new GameState(atlanta, map, 1, 4, null, new Deck<City>(map.allCities, true, false)); gs = gs.drawPlayerCards(gs.currentPlayer(), 1); Assert.IsFalse(gs.hasLost()); gs = gs.drawPlayerCards(gs.currentPlayer(), 2); Assert.IsTrue(gs.hasLost()); }
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); }