Advertisement
Guest User

player.java

a guest
Dec 13th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.06 KB | None | 0 0
  1. package Pandemic.player;
  2. import Pandemic.Gameboard.GameBoard;
  3. import Pandemic.Gameboard.SimulatePandemic;
  4. import Pandemic.cities.City;
  5. import Pandemic.cities.CityList;
  6. import Pandemic.variables.Disease;
  7. import Pandemic.variables.Piece;
  8. import Pandemic.variables.Variables;
  9. import Pandemic.actions.*;
  10.  
  11. import java.io.*;
  12. import java.util.*;
  13.  
  14. public class Player{
  15.  
  16. String playerName;
  17. int tactic;
  18. String playerRole;
  19. String tmpRole;
  20. GameBoard pandemicBoard;
  21. Piece playerPiece;
  22. int playerAction; //number of action per turn for each player
  23. boolean activePlayer;
  24. public ArrayList<City> hand ; //hand_cards maybe from action
  25. ArrayList<City> tmpFriendHand;
  26. String[] possibleColour = {"Red","Blue","Yellow","Black"};
  27. ArrayList<Action> suggestions = new ArrayList<Action>();
  28. City tmpLocation ;
  29.  
  30. final int MAX_DEPTH = 4; //Depth of the heuristic_function
  31.  
  32. ArrayList<Action> max_score_sequence = new ArrayList<Action>();
  33. float max_score= 0;
  34. int numOfRounds = 0;
  35.  
  36. boolean ExecuteFlag = false;
  37. boolean friendPlaying = false;
  38.  
  39.  
  40.  
  41. //------------for storing
  42. private ArrayList<City> freezeCities = new ArrayList<City>();
  43. private int f_redCube,f_blueCubes,f_yellowCubes,f_blackCubes;
  44. //private ArrayList<Disease> f_diseases = new ArrayList<Disease>();
  45. private ArrayList<City> f_ResearchStation = new ArrayList<City>();
  46. private City f1_location,f2_location,f3_location,f4_location;
  47. private boolean diseasesCured[] = new boolean[4];
  48. private ArrayList<City> freezeHand = new ArrayList<City>();
  49. //--------------to return
  50.  
  51. /*
  52. * Constructor for objects of class Player
  53. */
  54.  
  55. /* History of Actions
  56.  
  57.  
  58. */
  59. public Player(String pName,String pRole)
  60. {
  61. playerName = pName;
  62. hand = new ArrayList<City>();
  63. playerAction = 4;
  64. tactic = 50;
  65. playerRole = pRole;
  66. numOfRounds = 0;
  67.  
  68. }
  69.  
  70. public void setGameBoard(GameBoard currentBoard) { pandemicBoard = currentBoard; }
  71.  
  72. public void setPlayerPiece(Piece newPiece) { playerPiece = newPiece; }
  73.  
  74. public ArrayList<Action> getSuggestions() { return suggestions; }
  75.  
  76. public void setSuggestions(ArrayList<Action> suggestions) {this.suggestions = suggestions; }
  77.  
  78. /*
  79. *draw @param numberOfCards from playerPile and check if it is epidemic
  80. *and call @resolveEpidemic() or draw to @hand()
  81. */
  82. public void drawCard(int numberOfCards)
  83. {
  84. // draws a card for the player from the board
  85. for (int i = 0; i<numberOfCards; i++)
  86. {
  87. if (pandemicBoard.playerPile.size()!= 0)
  88. {
  89. //first element from array list PlayerPile
  90. if (pandemicBoard.playerPile.get(0).equals(Variables.isEpidemic)) {
  91. System.out.println("-----EPIDEMIC DRAWN!-----");
  92. pandemicBoard.resolveEpidemic();//follow the steps for epidemic event
  93. }
  94. else
  95. {
  96. //adds a new card to the players hand.
  97. hand.add((City) pandemicBoard.playerPile.get(0));
  98. }
  99. pandemicBoard.playerPile.remove(0);//remove the card from PlayerDeck
  100. System.out.println(this.getPlayerName() + " draws a card");
  101. }
  102. else
  103. {
  104. System.out.println("no more cards left");
  105. }
  106. }
  107. }
  108.  
  109.  
  110. /*
  111. * Count how many cards with a specific colour
  112. * player has in his hands
  113. * @param colour
  114. */
  115. public int getCountXCards(String colour)
  116. {
  117. int toReturn = 0;
  118. for (int i = 0 ; i < hand.size(); i++)
  119. {
  120. if (hand.get(i).getColour().equals(colour))
  121. {
  122. toReturn ++;
  123. }
  124. }
  125. return toReturn;
  126. }
  127.  
  128. /*
  129. * remove a card from hand ,
  130. * then calls methods to put it in the discard pile()
  131. * and remove the card from the hand.
  132. */
  133. public void discardCard(String cardName)
  134. {
  135. int toDiscard =0;
  136. for (int i = 0; i < getHand().size(); i++)
  137. {
  138. if (cardName.equals(getHand().get(i).getName())){
  139. //System.out.println("found matching card in hand");
  140. toDiscard=i;
  141. }
  142. }
  143. pandemicBoard.addPlayerCardDiscard(hand.get(toDiscard));//remove from playerDeck to put in PlayerDiscardDeck
  144. hand.remove(toDiscard);
  145. }
  146.  
  147. //discard all the cards needed for cure
  148. public void discardCureCards(String colour,int numberToDiscard)
  149. {
  150. for (int i = 0 ; i < numberToDiscard ; i ++)
  151. {
  152. for (int x = 0 ; x < hand.size(); x++ )
  153. {
  154. if (hand.get(x).getColour().equals(colour))
  155. {
  156. discardCard(hand.get(x).getName());
  157. break;
  158. }
  159. }
  160. }
  161. }
  162.  
  163. //get PlayerAction
  164. public int getPlayerAction(){ return playerAction; }
  165.  
  166. //decrease the playerAction (Max=4)
  167. public void decreasePlayerAction(){ playerAction--;}
  168.  
  169. // sets a players action back to 4
  170. public void resetPlayerAction() {
  171. System.out.println("?????????");
  172. playerAction=4; }
  173.  
  174. //return the name of player
  175. public String getPlayerName() { return playerName; }
  176.  
  177. // Returns an array with the players cards in hand
  178. public ArrayList<City> getHand() { return hand; }
  179.  
  180. public String getPlayerRole() {return playerRole; }
  181.  
  182. public void setPlayerRole(String playerRole) {this.playerRole = playerRole; }
  183.  
  184. public Piece getPlayerPiece() { return playerPiece; }
  185.  
  186. /**********************************************************************************
  187. *******These are the main (7+4) methods used to control the players actions********
  188. **********************************************************************************/
  189.  
  190. //Build research station as OPERATIONS_EXPERT
  191.  
  192.  
  193. //Build research station
  194. public boolean buildResearchStation ()
  195. {
  196.  
  197. buildResearchStation tmp = new buildResearchStation(playerPiece.getLocation(),getHand());
  198. if (playerRole.equals("OPERATIONS_EXPERT") && !Variables.CITY_WITH_RESEARCH_STATION.contains(playerPiece.getLocation()))
  199. {
  200. Variables.ADD_CITY_WITH_RESEARCH_STATION(playerPiece.getLocation());
  201.  
  202. if(ExecuteFlag) {
  203. System.out.println("building a research station in " + playerPiece.getLocation().getName());
  204. suggestions.add(tmp);
  205. decreasePlayerAction();
  206. }
  207. return true;
  208. }
  209. else
  210. {
  211. if (tmp.isaLegalMove())
  212. {
  213. discardCard(playerPiece.getLocation().getName());
  214. Variables.ADD_CITY_WITH_RESEARCH_STATION(playerPiece.getLocation());
  215. if(ExecuteFlag) {
  216. System.out.println("building a research station in " + playerPiece.getLocation().getName());
  217. suggestions.add(tmp);
  218. decreasePlayerAction();
  219. }
  220. return true;
  221. }
  222. }
  223. return false;
  224. }
  225.  
  226. //Treat disease action
  227. public boolean treatDisease (City location, String colour) {
  228.  
  229. treatDisease tmp = new treatDisease(location,colour);
  230. if (playerRole.equals("MEDIC")) {
  231. if(tmp.isaLegalMove()==true && location == playerPiece.getLocation())
  232. {
  233. if(ExecuteFlag)
  234. System.out.println("Removing all " + colour + " cube from " + location.getName());
  235. int abc = location.getCubeColour(colour);
  236. for (int i=0;i<abc;i++) {
  237. //System.out.println(i);
  238. location.removeCube(colour);
  239. if(ExecuteFlag) {
  240. pandemicBoard.addCube(colour);//add in pool of cube
  241. decreasePlayerAction();
  242. }
  243. }
  244.  
  245. if(ExecuteFlag)
  246. suggestions.add(tmp);
  247. return true;
  248. }
  249. }
  250. else {
  251. if(tmp.isaLegalMove()==true && location == playerPiece.getLocation())
  252. {
  253. if(ExecuteFlag)
  254. System.out.println("Removing a " + colour + " cube from " + location.getName());
  255. location.removeCube(colour);
  256. if(ExecuteFlag) {
  257. pandemicBoard.addCube(colour);//add in pool of cube
  258. suggestions.add(tmp);
  259. decreasePlayerAction();
  260. }
  261.  
  262.  
  263. return true;
  264. }
  265. }
  266. return false;
  267. }
  268.  
  269.  
  270.  
  271. // Drive action
  272. public boolean driveCity (City location, City destination)
  273. {
  274. // System.out.println(getPlayerName() + " current location is in " + location);
  275. // System.out.println("and he wants to go in " + destination);
  276.  
  277. // System.out.println("attempting to move " + getPlayerName() + " to " + destination.getName() + " from "+ location.getName());
  278. driveCity tmp = new driveCity(location,destination);
  279. if (tmp.isaLegalMove())
  280. {
  281. if(ExecuteFlag)
  282. System.out.println(getPlayerName() + " drives from " + location.getName() + " to " + destination.getName() + ".");
  283. playerPiece.setLocation(destination);
  284.  
  285. if(ExecuteFlag)
  286. suggestions.add(tmp);
  287. decreasePlayerAction();
  288. return true;
  289. }
  290. else
  291. {
  292. System.out.println("the location isn't connected");
  293. //decreasePlayerAction();
  294. }
  295. return false;
  296. }
  297.  
  298. // Charter Flight action
  299. public boolean charterFlight(City location, City destination)
  300. {
  301. // System.out.println(getPlayerName() + " wants to flying from " +
  302. // location.getName() + " to "+ destination.getName() +
  303. // " on a charter flight");
  304. charterFlight tmp = new charterFlight(location,getHand(),destination);
  305. if (tmp.isaLegalMove() && playerPiece.getLocation().equals(location))
  306. {
  307. if(ExecuteFlag)
  308. System.out.println(getPlayerName() + " takes a charter flight to " +
  309. destination.getName() + " from " + location.getName() );
  310. discardCard(location.getName());
  311. playerPiece.setLocation(destination);
  312.  
  313. if(ExecuteFlag) {
  314. suggestions.add(tmp);
  315. decreasePlayerAction();
  316. }
  317. return true;
  318. }
  319. return false;
  320. }
  321.  
  322. //Direct flight
  323. public boolean directFlight(City location, City destination)
  324. {
  325. // System.out.println(getPlayerName() + " wants to flying from " +
  326. // location.getName() + " to "+ destination.getName() +
  327. // " on a direct flight");
  328. directFlight tmp = new directFlight(destination,getHand());
  329. if (tmp.isaLegalMove())
  330. {
  331. if(ExecuteFlag) {
  332. System.out.println(getPlayerName() + " takes a direct flight to " +
  333. destination.getName() + " from " + location.getName() );
  334. decreasePlayerAction();
  335. }
  336. discardCard(destination.getName());
  337. playerPiece.setLocation(destination);
  338.  
  339. if(ExecuteFlag)
  340. suggestions.add(tmp);
  341. return true;
  342. }
  343. return false;
  344. }
  345.  
  346. //ShuttleFlight
  347. public boolean shuttleFlight(City location, City destination)
  348. {
  349. // System.out.println(getPlayerName() + " wants to flying from " +
  350. // location.getName() + " to "+ destination.getName() +
  351. // " on a shuttle flight");
  352. shuttleFlight tmp = new shuttleFlight(location,destination);
  353. if(tmp.isaLegalMove())
  354. {
  355. if(ExecuteFlag)
  356. System.out.println(getPlayerName() + " takes a shuttle flight to " +
  357. destination.getName() + " from " + location.getName() );
  358. playerPiece.setLocation(destination);
  359.  
  360. if(ExecuteFlag) {
  361. suggestions.add(tmp);
  362. decreasePlayerAction();
  363. }
  364. return true;
  365. }
  366. return false;
  367. }
  368.  
  369. // Discover Cure action
  370. public boolean discoverCure(City location, String colour)
  371. {
  372. discoverCure tmp = new discoverCure(location,getHand(),colour);
  373. if (playerRole.equals("SCIENTIST")) {
  374. if (tmp.isaLegalMove(1))
  375. {
  376. if(ExecuteFlag)
  377. System.out.println("Its possible to discover a cure");
  378. discardCureCards(colour,pandemicBoard.getNeededForCure()-1);
  379. pandemicBoard.cureDisease(colour);
  380.  
  381. if(ExecuteFlag) {
  382. suggestions.add(tmp);
  383. decreasePlayerAction();
  384. }
  385. return true;
  386. }
  387. }
  388. else
  389. {
  390. if (tmp.isaLegalMove(0))
  391. {
  392. if(ExecuteFlag)
  393. System.out.println("Its possible to discover a cure");
  394. discardCureCards(colour,pandemicBoard.getNeededForCure());
  395. pandemicBoard.cureDisease(colour);
  396. if(ExecuteFlag) {
  397. suggestions.add(tmp);
  398. decreasePlayerAction();
  399. }
  400. return true;
  401. }
  402. }
  403. return false;
  404. }
  405.  
  406.  
  407. /*
  408. *Below are implemented
  409. *1) --> OPERATIONS_EXPERT special ability (build research station without to discard a card) is implemented as if in the @BuildResearchStaion method
  410. *2) --> MEDIC special ability (treat all the cubes of a specific colour) implemented in @treatDisease as if statement
  411. *3) --> SCIENTIST special ability is implemented as if in the classic cure disease
  412. *4) --> QUARANTINE_SPECIALIST special ability is implemented in @infectCityPhase in @GameBoard class
  413. */
  414.  
  415. //---------------------------------------------------------------------------------
  416. /**********************************************************************************
  417. ***************** These methods are used for AI controlled players.****************
  418. **********************************************************************************/
  419. //---------------------------------------------------------------------------------
  420.  
  421.  
  422.  
  423. /** Design Doc: How should the other suggestions be evaluated
  424. - Run scoreDisese (enhanced) for each suggestions (if actions consist of buildResearch change the scoring)
  425. */
  426. @SuppressWarnings("unchecked")
  427. public void makeDecision(ArrayList<City> friend_hand,String Role)
  428. {
  429. ExecuteFlag = false;
  430.  
  431. suggestions.clear();
  432.  
  433. tmpLocation = playerPiece.getLocation();
  434.  
  435.  
  436. tmpFriendHand = (ArrayList<City>) hand.clone();
  437.  
  438. playerAction = 4;
  439. tmpRole = playerRole;
  440. playerRole = Role;
  441.  
  442. for(Piece p : pandemicBoard.playerPieces ){
  443. //System.out.println(p.owner.getPlayerRole() + " Location : " + p.owner.playerPiece.getLocation());
  444. if(p.owner.getPlayerRole().equals(playerRole)) {
  445. playerPiece.setLocation(p.getLocation());
  446. //System.out.println("Set new location : " + p.getLocation());
  447. //break;
  448. }
  449. }
  450.  
  451. if(friend_hand != null) {
  452. //to set new location
  453. hand = (ArrayList<City>) friend_hand.clone();
  454. friendPlaying = true;
  455. }else{
  456. numOfRounds ++;
  457. friendPlaying = false;
  458. }
  459.  
  460. if(friend_hand == null) {
  461. System.out.println("--------------------------------------------------------TURN: "+ numOfRounds+ " Actions left:" + playerAction );
  462. System.out.println(this.getPlayerName() + " is thinking..... "+ hand);
  463. }
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470. if(friend_hand == null){
  471. //TODO When its our turn(friend hand == null) Initialize/Renew Opponent modeling on Variables.Suggestions or Variables.Actions
  472. Float[] scoredSuggestions = new Float[4];
  473. int i = 0;
  474.  
  475.  
  476. for(ArrayList<Action> a : Variables.Suggestions ) {
  477. System.out.println(a);
  478. }
  479. System.out.println();
  480. for(ArrayList<Action> sequence : Variables.Suggestions) {
  481. if(sequence == null) {
  482. sequence = new ArrayList<Action>();
  483. }
  484. System.out.println();
  485. System.out.println(i);
  486. //System.out.println(sequence);
  487. if(sequence.size() != 0 ) {
  488.  
  489. freeze();
  490. scoredSuggestions[i] = scoreSuggestion(sequence);
  491. unfreeze();
  492.  
  493. System.out.println(scoredSuggestions[i]);
  494. }
  495.  
  496.  
  497. i++;
  498. }
  499.  
  500. }
  501.  
  502. /**********************************************************************************************************************************/
  503. max_score = -10000000;
  504. float temp_score = 0;
  505. playerAction = 4;
  506. max_score_sequence.clear();
  507. System.out.println("Location : " + playerPiece.getLocation().getName());
  508.  
  509. if(friend_hand != null) {
  510. freeze();
  511. }
  512. ExecuteFlag = true;
  513.  
  514.  
  515. while (enoughCardsForCure() && playerAction>0) {// may need to cure more than one Disease
  516. // System.out.println("might be worth trying to find a cure. disatnce : "+ getDistanceResearch());
  517.  
  518. if (discoverCure(playerPiece.getLocation(),tryCureCardColour())) {
  519. // System.out.println(this.getPlayerName() + " has discovered a cure!");
  520. temp_score += 100000;
  521. System.out.println("Yeah!!");
  522. System.out.println(" Yeah!!");
  523. System.out.println(" Yeah!!");
  524. }else
  525. { // enough cards for cure- drive to nearest research station
  526. // System.out.println("They need to go to a researh station.");
  527. while(playerAction >0) {
  528. tryDriveResearchStation();
  529. System.out.println(tryCureCardColour());
  530. if(playerAction > 0) {
  531. if(discoverCure(playerPiece.getLocation(),tryCureCardColour())) {
  532. //System.out.println(this.getPlayerName() + " has discovered a cure!");
  533. temp_score += 100000;
  534. System.out.println("Yeah!!");
  535. System.out.println(" Yeah!!");
  536. System.out.println(" Yeah!!");
  537. break;
  538. }
  539. }
  540. }
  541.  
  542. }
  543.  
  544. }
  545. //TODO check if we ever lose from not being able to drive to a research station
  546.  
  547. ExecuteFlag = false;
  548.  
  549.  
  550. if(friend_hand == null) {
  551. freeze();
  552. }
  553. heuristic(4-playerAction, pandemicBoard.getCities(),hand,temp_score,max_score_sequence,Variables.CITY_WITH_RESEARCH_STATION);
  554.  
  555. unfreeze();
  556. /**********************************************************************************************************************************/
  557.  
  558.  
  559. //TODO Consider Variables.Suggestions too and choose the best action with the help of opponent Modeling
  560.  
  561. if(! friendPlaying )
  562. System.out.println("Max Score: "+ max_score + " " + max_score_sequence + " hand : "+ hand + " Research Staions: "+ Variables.CITY_WITH_RESEARCH_STATION + " Player Role: " + playerRole);
  563.  
  564.  
  565. hand = (ArrayList<City>) tmpFriendHand.clone();
  566.  
  567.  
  568.  
  569. //System.out.println("Location : " + playerPiece.getLocation().getName());
  570. ExecuteFlag = true;
  571. //playerAction = 4;
  572.  
  573.  
  574. if(friend_hand == null) {
  575.  
  576. for(Action act: max_score_sequence) {
  577.  
  578. for(City c :pandemicBoard.cities){
  579. if(c.getName() == playerPiece.getLocation().getName()) {
  580. playerPiece.setLocation(c);
  581. break;
  582. }
  583. }
  584. //System.out.println("Current location : " + playerPiece.getLocation().getName());
  585.  
  586. if(act instanceof driveCity){
  587. if(!driveCity(((Pandemic.actions.driveCity) act).getMoveFrom(),((Pandemic.actions.driveCity) act).getMoveTo())) {
  588. System.out.println("Drive city error");
  589. System.exit(1);
  590. }
  591.  
  592.  
  593. }else if(act instanceof charterFlight){
  594. if(! charterFlight(((charterFlight) act).getMoveFrom(),((charterFlight) act).getMoveTo()))
  595. System.exit(0);
  596.  
  597. }else if(act instanceof directFlight){
  598. if(!directFlight(playerPiece.getLocation(), ((Pandemic.actions.directFlight) act).getMoveTo())){
  599. System.out.println("Direct flight error");
  600. System.out.println("Destination: " + ((Pandemic.actions.directFlight) act).getMoveTo());
  601. System.exit(1);
  602. }
  603.  
  604. }else if(act instanceof buildResearchStation){
  605. if(!buildResearchStation()){
  606. System.out.println("buildResearchStation error");
  607. System.out.println("City to Build: " + ((buildResearchStation) act).getCityToResearchStation());
  608. System.exit(1);
  609. }
  610.  
  611. }else if(act instanceof discoverCure){
  612. if(!discoverCure(playerPiece.getLocation(), ((Pandemic.actions.discoverCure) act).getColorOfDisease())){
  613. System.out.println("discoverCure error");
  614. System.exit(1);
  615. }
  616.  
  617. }else if(act instanceof shuttleFlight){
  618. if(!shuttleFlight(((Pandemic.actions.shuttleFlight) act).getMoveFrom(), ((Pandemic.actions.shuttleFlight) act).getMoveTo())){
  619. System.out.println("shuttleFlight error");
  620. System.exit(1);
  621. }
  622.  
  623. }else if(act instanceof treatDisease){
  624. if(!treatDisease(playerPiece.getLocation(), ((Pandemic.actions.treatDisease) act).getColour())){
  625. System.out.println("treatDisease error");
  626. for(City c :pandemicBoard.cities){
  627. if(c.getMaxCube() >0) {
  628. System.out.println("City "+ c.getName() + " " + c.getMaxCube());
  629. }
  630. }
  631.  
  632. System.out.println(((treatDisease) act).getLocation().getCubeColour("Red"));
  633. System.out.println(((treatDisease) act).getLocation().getCubeColour("Black"));
  634. System.out.println(((treatDisease) act).getLocation().getCubeColour("Yellow"));
  635. System.out.println(((treatDisease) act).getLocation().getCubeColour("Blue"));
  636. System.exit(1);
  637. }
  638.  
  639. }else{
  640. //not supposed to reach this
  641. System.out.println("...");
  642.  
  643. System.exit(1);
  644. }
  645. }
  646.  
  647. System.out.println("Done the Actions Correct? hand : "+ hand + " Research Staions: "+ Variables.CITY_WITH_RESEARCH_STATION + " Remaining Actions: ");
  648. //System.out.println("Suggestions: "+ suggestions);
  649.  
  650. // for(City c :pandemicBoard.cities){
  651. // if(c.getMaxCube() >0) {
  652. // System.out.println("City "+ c.getName() + " " + c.getMaxCube());
  653. // }
  654. // }
  655. System.out.println("Red cubes: "+pandemicBoard.redCubes);
  656. System.out.println("Black cubes: "+pandemicBoard.blackCubes);
  657. System.out.println("Yellow cubes: "+pandemicBoard.yellowCubes);
  658. System.out.println("Blue cubes: "+pandemicBoard.blueCubes);
  659.  
  660.  
  661. System.out.println("Red Disease: " + pandemicBoard.getDisease("Red").cured);
  662. System.out.println("Black Disease: " + pandemicBoard.getDisease("Black").cured);
  663. System.out.println("Yellow Disease: " + pandemicBoard.getDisease("Yellow").cured);
  664. System.out.println("Blue Disease: " + pandemicBoard.getDisease("Blue").cured);
  665. System.out.println("Outbreak level: "+ Variables.OUTBREAK_MARKER);
  666.  
  667. if(suggestions.size() < 4) {
  668. System.out.println("suggestions.size()");
  669. System.exit(1);
  670. }
  671. //System.exit(1);
  672. return;
  673. }else if(friend_hand != null) {
  674. suggestions.addAll(max_score_sequence);
  675. System.out.println("Suggestions from "+ playerName + " Actions : "+ suggestions);
  676. if(suggestions.size()<4 || suggestions.size()>4 ) {
  677. System.out.println("Suggetion error");
  678. System.exit(1);
  679. }
  680. //Revert back to normal player variables
  681. unfreeze();
  682.  
  683. playerRole = tmpRole;
  684. hand = (ArrayList<City>) tmpFriendHand.clone();
  685. playerPiece.setLocation(tmpLocation);
  686. playerAction = 0;
  687. return;
  688. }
  689.  
  690.  
  691. }
  692.  
  693. @SuppressWarnings("unchecked")
  694. public void freeze() {
  695. freezeCities = (ArrayList<City>) pandemicBoard.getCities().clone();
  696. freezeHand = (ArrayList<City>) hand.clone();
  697. f_redCube = pandemicBoard.redCubes;
  698. f_blueCubes = pandemicBoard.blueCubes;
  699. f_yellowCubes = pandemicBoard.yellowCubes;
  700. f_blackCubes = pandemicBoard.blackCubes;
  701. // f_diseases = (ArrayList<Disease>) pandemicBoard.getDiseases().clone();
  702.  
  703. for(int i=0; i<4; i++) {
  704. diseasesCured[i] = pandemicBoard.diseases.get(i).getCured();
  705. }
  706. f_ResearchStation = (ArrayList<City>) pandemicBoard.getResearchCentre().clone();
  707. f1_location = pandemicBoard.playerPieces[0].getLocation();
  708. f2_location = pandemicBoard.playerPieces[1].getLocation();
  709. f3_location = pandemicBoard.playerPieces[2].getLocation();
  710. f4_location = pandemicBoard.playerPieces[3].getLocation();
  711.  
  712. }
  713.  
  714.  
  715. public void unfreeze() {
  716. pandemicBoard.cities = (ArrayList<City>) freezeCities;
  717. hand = freezeHand;
  718. pandemicBoard.redCubes = f_redCube;
  719. pandemicBoard.blueCubes = f_blueCubes;
  720. pandemicBoard.yellowCubes = f_yellowCubes;
  721. pandemicBoard.blackCubes = f_blackCubes;
  722. //pandemicBoard.diseases = (ArrayList<Disease>) f_diseases.clone();
  723. for(int i=0; i<4; i++) {
  724. pandemicBoard.diseases.get(i).setCured(diseasesCured[i]);
  725. }
  726. pandemicBoard.playerPieces[0].setLocation(f1_location);
  727. pandemicBoard.playerPieces[1].setLocation(f2_location);
  728. pandemicBoard.playerPieces[2].setLocation(f3_location);
  729. pandemicBoard.playerPieces[3].setLocation(f4_location);
  730. Variables.CITY_WITH_RESEARCH_STATION = f_ResearchStation;
  731.  
  732. }
  733.  
  734.  
  735.  
  736.  
  737. //an attempt to drive to nearest research station
  738. public void tryDriveResearchStation()
  739. {
  740. System.out.println("Searching cities with research stations as destinations.");
  741. getDistances(pandemicBoard.getResearchLocations());
  742. // System.out.println("Calculating destination");
  743. City toDriveTo = calculateDestination();
  744. System.out.println("I'll try to drive to " + toDriveTo.getName());
  745. driveCity(playerPiece.getLocation(),toDriveTo);
  746. }
  747.  
  748.  
  749.  
  750. /**
  751. * Check to see if the count of cards in any color equal the number required
  752. * for a cure
  753. **/
  754. public String tryCureCardColour()
  755. {
  756. int n = pandemicBoard.getNeededForCure();
  757. if (playerRole == "SCIENTIST") {
  758. n --;
  759. }
  760. for (int i = 0; i < pandemicBoard.getNumberColours(); i ++)
  761. {
  762. if (getCountXCards(possibleColour[i]) >=n && !pandemicBoard.getDisease(possibleColour[i]).cured)
  763. {
  764. return possibleColour[i];
  765. }
  766. }
  767. return null;
  768. }
  769.  
  770. //get distance
  771. public int getDistanceResearch()
  772. {
  773. getDistances(pandemicBoard.getResearchLocations());
  774. return playerPiece.getLocation().getDistance();
  775. }
  776.  
  777. //get distances of the cities which a look to travel
  778. public void getDistances(ArrayList<City> destinations)
  779. {
  780. pandemicBoard.resetDistances();
  781. setDestination(destinations);
  782. int distance = 1;
  783. while (playerPiece.getLocation().getDistance() == 9999999)
  784. {
  785. // System.out.println("Looking for places distance of " + distance);
  786. for (int i = 0 ; i < pandemicBoard.cities.size() ; i ++)
  787. {
  788.  
  789. for (int x = 0 ; x < pandemicBoard.cities.get(i).getNeighbors().size() ; x ++)
  790. {
  791. if (pandemicBoard.cities.get(i).getDistance() == (distance-1)
  792. && pandemicBoard.cities.get(i).getNeighbors().get(x).getDistance() > distance)
  793. {
  794. pandemicBoard.cities.get(i).getNeighbors().get(x).setDistance(distance);
  795. }
  796. }
  797.  
  798. }
  799. distance ++;
  800. }
  801.  
  802. }
  803.  
  804. public void setDestination(ArrayList<City> destinations)
  805. {
  806. for (int i = 0 ; i < destinations.size() ; i ++)
  807. {
  808. destinations.get(i).setDistance(0);
  809. }
  810. }
  811.  
  812. public City calculateDestination()
  813. {
  814. int closestDestination = 9999999;
  815. City toReturn = new City(0,0,0,0,0);
  816. //System.out.println("i have: " +playerPiece.getLocationConnections().size() + " neighbors");
  817. for (int i = 0 ; i < playerPiece.getLocationConnections().size(); i++)
  818. {
  819. if (playerPiece.getLocationConnections().get(i).getDistance() < closestDestination)
  820. {
  821. //System.out.println("Will probably go to " + playerPiece.getLocationConnections()[i].getName());
  822. toReturn = playerPiece.getLocationConnections().get(i);
  823. closestDestination = playerPiece.getLocationConnections().get(i).getDistance();
  824. }
  825.  
  826. }
  827. return toReturn;
  828. }
  829.  
  830.  
  831.  
  832.  
  833. /*
  834. 1)Check if we should a build a research station before we move (OPERATIONS_EXPERT may favor just building a researh station)
  835. 2)Check if we should use some sort of flight (check all cards in hand for both types of flight)
  836. 3)Count how many actions you need to take to more there
  837. 4)
  838. */
  839.  
  840. //Check if player has enough cards to cure
  841. public boolean enoughCardsForCure(){
  842. int n = 4;
  843. if (playerRole == "SCIENTIST")
  844. n--;
  845. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  846.  
  847. for(City i : hand)
  848. if (i.getColour() == "Red")
  849. redcards++;
  850. else if (i.getColour() == "Yellow")
  851. yellowcards++;
  852. else if (i.getColour() == "Blue")
  853. bluecards++;
  854. else
  855. blackcards++;
  856. return ((n <= redcards && !pandemicBoard.getDisease("Red").cured) ||(n <= blackcards && !pandemicBoard.getDisease("Black").cured)
  857. || (n <= bluecards && !pandemicBoard.getDisease("Blue").cured) ||(n <= yellowcards && !pandemicBoard.getDisease("Yellow").cured));
  858. }
  859.  
  860.  
  861.  
  862. //Author: @Stavros
  863. //Write best possible moves in a List of Actions as the result
  864. @SuppressWarnings("unchecked")
  865. private void heuristic(int depth, ArrayList<City> cityBoard, ArrayList<City> currentHand, float score,ArrayList<Action> actionSequence,List<City> researchStations){
  866. LinkedList<Action> possibleActions;// = new LinkedList<Action>();
  867. int temp_weight = 0;
  868. int index = 0;
  869. int max_cube = 0;
  870. int cubesToAdd = 0;
  871. String max_cube_color = null;
  872. float tmp_score_before = 0;
  873. float tmp_score_after = 0;
  874. boolean worthToExpand = true;
  875.  
  876. ArrayList<Action> temp_actionSequence;// = new ArrayList<Action>() ;
  877.  
  878. //Freezing current Situation
  879. City playerCity = playerPiece.getLocation();
  880. ArrayList<City> freezeCities = (ArrayList<City>) pandemicBoard.getCities().clone();
  881. //ArrayList<City> freezeCities = (ArrayList<City>) cityBoard.clone();
  882.  
  883. ArrayList<City> tmpHand = new ArrayList<City>();
  884.  
  885.  
  886. for(City c :pandemicBoard.cities){
  887. if(c.getName() == playerPiece.getLocation().getName()) {
  888. playerPiece.setLocation(c);
  889. break;
  890. }
  891. }
  892.  
  893. max_cube = playerPiece.getLocation().getMaxCube();
  894.  
  895. //exit condition
  896. if(depth < MAX_DEPTH){
  897.  
  898.  
  899. //Explore all possible actions (possibleActions)
  900. possibleActions = getPossibleActions(currentHand,playerPiece.getLocation());
  901. //System.out.println("----------Depth: "+ depth+ " Actions: "+ possibleActions + " Location: "+ playerPiece.getLocation().getName()+ " Hand: "+ currentHand +" Score: " + score);
  902.  
  903. for(Action act : possibleActions){
  904. temp_actionSequence = (ArrayList<Action>) actionSequence.clone();
  905.  
  906. tmpHand = (ArrayList<City>) currentHand.clone();
  907. temp_weight = 0;
  908. playerPiece.setLocation(playerCity);
  909. Variables.CITY_WITH_RESEARCH_STATION = new ArrayList<City>(researchStations);
  910. pandemicBoard.cities = (ArrayList<City>) cityBoard.clone();
  911.  
  912. hand = (ArrayList<City>) currentHand.clone();
  913. worthToExpand = true;
  914.  
  915. for(City c :pandemicBoard.cities){
  916. if(c.getMaxCube() >0) {
  917. // System.out.println("City "+ c.getName() + " " + c.getMaxCube());
  918. }
  919. if(c.getName() == playerPiece.getLocation().getName()) {
  920. //System.out.println("City "+ c.getName() + " " + c.getMaxCube());
  921. // System.out.println("MATCH");
  922. playerPiece.setLocation(c);
  923. break;
  924. }
  925.  
  926. }
  927.  
  928. //System.out.println("Depth: "+ depth+ " " + act + " Location: "+ playerPiece.getLocation().getName()+ " Hand: "+ currentHand);
  929.  
  930. // Do the action !!!!!!!!!
  931.  
  932. if(act instanceof driveCity){
  933. if(!driveCity(((Pandemic.actions.driveCity) act).getMoveFrom(),((Pandemic.actions.driveCity) act).getMoveTo())){
  934. System.out.println("driveCity error");
  935. System.exit(1);
  936. }
  937.  
  938. }else if(act instanceof charterFlight){
  939. temp_weight += flightScoreCalculator(playerPiece.getLocation());
  940. if (temp_weight == -1000){
  941. worthToExpand = false;
  942. }
  943.  
  944. if(! charterFlight(playerPiece.getLocation(), ((charterFlight) act).getMoveTo())) {
  945. System.out.println("Charter flight error Heuristic");
  946. System.exit(0);
  947. }
  948.  
  949. tmpHand.remove( ((charterFlight) act).getMoveFrom());
  950.  
  951. }else if(act instanceof directFlight){
  952. temp_weight += flightScoreCalculator(((directFlight) act).getMoveTo());
  953. if (temp_weight == -1000){
  954. worthToExpand = false;
  955. }
  956. //System.out.println(tmpHand);
  957.  
  958. if(!directFlight(playerPiece.getLocation(), ((Pandemic.actions.directFlight) act).getMoveTo())){
  959. System.out.println("Direct flight error Heuristic");
  960. System.exit(1);
  961. }
  962.  
  963. tmpHand.remove(((directFlight) act).getMoveTo());
  964.  
  965. }else if(act instanceof buildResearchStation){
  966. temp_weight += score_ResearchStation(((buildResearchStation) act).getCityToResearchStation());
  967. if (temp_weight == -1000){
  968. worthToExpand = false;
  969. }
  970. //System.out.println("+++++++++++++++++++++ " + tmpHand);
  971. //System.out.println("research stations before : "+ Variables.CITY_WITH_RESEARCH_STATION);
  972. if(!buildResearchStation()){
  973. System.out.println("buildResearchStation error Heuristic");
  974. System.exit(1);
  975. }
  976. //System.out.println("research stations after : "+ Variables.CITY_WITH_RESEARCH_STATION);
  977.  
  978. if( playerRole != "OPERATIONS_EXPERT") {
  979. index = 0;
  980. for(City c : tmpHand) {
  981. if(c.getName() == playerPiece.getLocation().getName()) {
  982. break;
  983. }
  984. index ++;
  985. }
  986.  
  987. if(index == tmpHand.size()) {
  988. System.out.println("Error action build Heuristic");
  989. System.exit(1);
  990. }
  991. tmpHand.remove(index);
  992. }
  993. //System.out.println("+++--------++++++++++++++++++ " + tmpHand);
  994.  
  995. }else if(act instanceof discoverCure){
  996. temp_weight += 0;
  997. if(!discoverCure(playerPiece.getLocation(), ((Pandemic.actions.discoverCure) act).getColorOfDisease())){
  998. System.out.println("discoverCure error Heuristic");
  999. System.exit(1);
  1000. }
  1001.  
  1002. }else if(act instanceof shuttleFlight){
  1003. if(!shuttleFlight(((Pandemic.actions.shuttleFlight) act).getMoveFrom(), ((Pandemic.actions.shuttleFlight) act).getMoveTo())){
  1004. System.out.println("shuttleFlight error Heuristic");
  1005. System.exit(1);
  1006. }
  1007.  
  1008. }else if(act instanceof treatDisease){
  1009. //int tmpCubesBefore = playerPiece.getLocation().getCubeColour(((Pandemic.actions.treatDisease) act).getColour());
  1010. //System.out.println("Depth: "+ depth+ " " + act + " Location: "+ playerPiece.getLocation().getName()+ " Hand: "+ currentHand);
  1011. //TODO MAY NEED TO CHECK FOR OTHER COLOR CUBES
  1012. max_cube = playerPiece.getLocation().getMaxCube();
  1013. max_cube_color = ((treatDisease) act).getColour();
  1014. //System.out.println("INIT TREAT cubes: "+ playerPiece.getLocation().getMaxCube());
  1015.  
  1016. //System.out.println(((treatDisease) act).getColour() + " CUBES: " + playerPiece.getLocation().getMaxCube());
  1017.  
  1018. //tmp_score_before = scoreDiseases(((treatDisease) act).getLocation());
  1019. if(!treatDisease(playerPiece.getLocation(), ((Pandemic.actions.treatDisease) act).getColour())){
  1020. System.out.println("treatDisease error Heuristic");
  1021. System.exit(1);
  1022. }
  1023. cubesToAdd = max_cube - playerPiece.getLocation().getMaxCube();
  1024. //System.out.println("INIT TREAT cubes after: "+ playerPiece.getLocation().getMaxCube());
  1025.  
  1026. //int tmpCubesAfter = playerPiece.getLocation().getCubeColour(((Pandemic.actions.treatDisease) act).getColour());
  1027. //tmp_score_after = scoreDiseases(((treatDisease) act).getLocation());
  1028. //temp_weight += (tmpCubesBefore-tmpCubesAfter) * (tmp__score - score_diseases());
  1029. //System.out.println("INIT TREAT cubes: "+ playerPiece.getLocation().getMaxCube());
  1030. //System.out.println("-----------"+ (tmp_score_before - tmp_score_after)+ " "+ ((Pandemic.actions.treatDisease) act).getLocation().getName());
  1031. //temp_weight += tmp_score_before - tmp_score_after;
  1032. temp_weight += 100;
  1033. }else{
  1034. //not supposed to reach this
  1035. System.out.println("Howw?????");
  1036. System.exit(1);
  1037. }
  1038. //Then explore the next level
  1039. if(!temp_actionSequence.add(act)){
  1040. System.out.println("Howw 2?????");
  1041. System.exit(1);
  1042. }
  1043.  
  1044. if(worthToExpand)
  1045. heuristic(depth + 1,freezeCities,tmpHand,score+temp_weight,temp_actionSequence,Variables.CITY_WITH_RESEARCH_STATION);
  1046. }
  1047.  
  1048. }else{
  1049. //System.out.println("MAX DETH_________________score: " + score + " "+currentHand);
  1050. //Evaluate board State
  1051.  
  1052.  
  1053. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  1054. boolean flag = false;
  1055.  
  1056. for(City i : hand)
  1057. if (i.getColour() == "Red")
  1058. redcards++;
  1059. else if (i.getColour() == "Yellow")
  1060. yellowcards++;
  1061. else if (i.getColour() == "Blue")
  1062. bluecards++;
  1063. else
  1064. blackcards++;
  1065.  
  1066.  
  1067. int n = 4;
  1068. int count = 0;
  1069. if (playerRole == "SCIENTIST")
  1070. n--;
  1071.  
  1072. if(redcards >= n-1 && ! pandemicBoard.getDisease("Red").cured){
  1073. count ++;
  1074. flag = true;
  1075. }else if(yellowcards >= n-1 && ! pandemicBoard.getDisease("Yellow").cured){
  1076. count ++;
  1077. flag = true;
  1078. }else if(bluecards >= n-1 && ! pandemicBoard.getDisease("Blue").cured){
  1079. count ++;
  1080. flag = true;
  1081. }else if(blackcards >= n-1 && ! pandemicBoard.getDisease("Black").cured ){
  1082. count ++;
  1083. flag = true;
  1084. }
  1085.  
  1086. if(flag && getDistanceResearch() <= 4-count){
  1087.  
  1088. if(numOfRounds >= 4){
  1089. score += 3000;
  1090. //System.out.println("+++\n\n\n\n\n\n\n\n\n\n\n");
  1091. }else{
  1092. score += 30;
  1093. }
  1094. }
  1095.  
  1096.  
  1097. if(playerRole == "QUARANTINE_SPECIALIST") {
  1098. score += scoreQuarantineSpecialist(playerPiece.getLocation()); //function to score his standing position specifically
  1099. }
  1100.  
  1101. if(score > max_score){
  1102. max_score_sequence = (ArrayList<Action>) actionSequence.clone();
  1103. max_score = score;
  1104. }
  1105. return;
  1106.  
  1107. }
  1108. //Reverting the Board to the initial State
  1109. pandemicBoard.cities = (ArrayList<City>) freezeCities.clone();
  1110. playerPiece.setLocation(playerCity);
  1111.  
  1112. for(City c :pandemicBoard.cities){
  1113. if(c.getName() == playerCity.getName()) {
  1114. for(int i=0; i<cubesToAdd && max_cube_color != null ;i++) {
  1115. c.addCube(max_cube_color);
  1116. }
  1117. playerPiece.setLocation(c);
  1118. break;
  1119. }
  1120. }
  1121.  
  1122. Variables.CITY_WITH_RESEARCH_STATION = new ArrayList<City>(researchStations);
  1123.  
  1124. //System.out.println("@kallinteris DEBUG1: hand" + tmpHand);
  1125. hand = (ArrayList<City>) tmpHand.clone();
  1126.  
  1127. }
  1128.  
  1129. /** Authors: @kallinteris-Andreas && @Misokalos
  1130. Returns: a list of all possible moves that can be executed by the player
  1131. */
  1132. private LinkedList<Action> getPossibleActions(ArrayList<City> currentHand, City currentLocation){
  1133. LinkedList<Action> possibleAction = new LinkedList<Action>();
  1134.  
  1135.  
  1136.  
  1137. //charterFlight @Kallinteris-Andreas
  1138. if(hand.contains(currentLocation))
  1139. for(City city : Variables.CITY_LIST) {
  1140. if(! city.getName().equals(currentLocation.getName()))
  1141. possibleAction.add(new charterFlight(currentLocation, hand,city));
  1142. }
  1143.  
  1144. //directFlight @Kallinteris-Andreas
  1145. for (City destination : currentHand) {
  1146. if(! destination.getName().equals(currentLocation.getName()))
  1147. possibleAction.add(new directFlight(destination, currentHand));
  1148. }
  1149.  
  1150. //driveCity @Kallinteris-Andreas
  1151. for(City neighbor : currentLocation.getNeighbors())
  1152. possibleAction.add(new driveCity(currentLocation, neighbor));
  1153. //shuttleFlight @kallinteris-Andreas
  1154. if (Variables.CITY_WITH_RESEARCH_STATION.contains(currentLocation))
  1155. for (City cityR : Variables.CITY_WITH_RESEARCH_STATION)
  1156. if (cityR.getName() != currentLocation.getName())
  1157. possibleAction.add(new shuttleFlight(currentLocation, cityR));
  1158.  
  1159. //System.out.println("Location: " + currentLocation.getName() + " Cubes: " + currentLocation.getMaxCube() );
  1160. if(currentLocation.getCubeColour("Red") != 0){
  1161. if(checktreatDisease(currentLocation, "Red")){
  1162. possibleAction.add(new treatDisease(currentLocation, "Red"));
  1163. }
  1164. }
  1165. else if(currentLocation.getCubeColour("Blue") != 0){
  1166. if(checktreatDisease(currentLocation, "Blue")){
  1167. possibleAction.add(new treatDisease(currentLocation, "Blue"));
  1168. }
  1169. }
  1170. else if(currentLocation.getCubeColour("Black") != 0){
  1171. if(checktreatDisease(currentLocation, "Black")){
  1172. possibleAction.add(new treatDisease(currentLocation, "Black"));
  1173. }
  1174. }
  1175. else if(currentLocation.getCubeColour("Yellow") != 0){
  1176. if(checktreatDisease(currentLocation, "Yellow")){
  1177. possibleAction.add(new treatDisease(currentLocation, "Yellow"));
  1178. }
  1179. }
  1180.  
  1181. //build station
  1182. //TODO TIDY up
  1183. if(checkbuildResearchStation(currentHand, currentLocation)){
  1184. buildResearchStation a = new buildResearchStation(currentLocation,currentHand);
  1185. possibleAction.add(a);
  1186. //System.out.println("@Kallinteris DEBUG0: checkbuildResearchStation hand: " + currentHand + " Action : "+ a);
  1187. }
  1188.  
  1189. //discover cure
  1190. // if(checkdiscoverCure(currentLocation, "Blue"))
  1191. // possibleAction.add(new discoverCure(currentLocation,getHand(), "Blue"));
  1192. // else if(checkdiscoverCure(currentLocation, "Black")){
  1193. // possibleAction.add(new discoverCure(currentLocation,getHand(), "Black"));
  1194. // }
  1195. // else if(checkdiscoverCure(currentLocation, "Red")){
  1196. // possibleAction.add(new discoverCure(currentLocation,getHand(), "Red"));
  1197. // }
  1198. // else if(checkdiscoverCure(currentLocation, "Yellow")){
  1199. // possibleAction.add(new discoverCure(currentLocation,getHand(), "Yellow"));
  1200. // }
  1201.  
  1202. return possibleAction;
  1203. }
  1204.  
  1205.  
  1206.  
  1207.  
  1208. //checking for legal Actions/////////
  1209. public boolean checkbuildResearchStation (ArrayList<City> currentHand, City currentLocation){
  1210. buildResearchStation tmp = new buildResearchStation(currentLocation, currentHand );
  1211. if (playerRole.equals("OPERATIONS_EXPERT") && !Variables.CITY_WITH_RESEARCH_STATION.contains(currentLocation)) {
  1212. return true;
  1213. }
  1214. else{
  1215. if (tmp.isaLegalMove()){
  1216. return true;
  1217. }
  1218. }
  1219. return false;
  1220. }
  1221. public boolean checktreatDisease (City location, String colour){
  1222.  
  1223. treatDisease tmp = new treatDisease(location,colour);
  1224. if (playerRole.equals("MEDIC")) {
  1225. if(tmp.isaLegalMove()==true && location.getName() == playerPiece.getLocation().getName()){
  1226. for (int i=0;i<location.getCubeColour(colour);i++) {
  1227. }
  1228. return true;
  1229. }
  1230. }
  1231. else {
  1232. if(tmp.isaLegalMove()==true && location.getName() == playerPiece.getLocation().getName()){
  1233. return true;
  1234. }
  1235. }
  1236. //System.out.println("--------------+============");
  1237. return false;
  1238. }
  1239.  
  1240. public boolean checkdiscoverCure(City location, String colour){
  1241. discoverCure tmp = new discoverCure(location,getHand(),colour);
  1242. if (playerRole.equals("SCIENTIST")) {
  1243. if (tmp.isaLegalMove(1)){
  1244. return true;
  1245. }
  1246. }
  1247. else{
  1248. if (tmp.isaLegalMove(0)){
  1249. return true;
  1250. }
  1251. }
  1252. return false;
  1253. }
  1254.  
  1255. private float score_ResearchStation(City discCity){
  1256. //reasearch Stations near x 40
  1257. //one research station x 10
  1258. //mutual coeff if players dont build increase
  1259. // too many stations x 40
  1260. //builder x 50
  1261.  
  1262. float scoreOpExp = 0,scoreNoReasearchStations = 0;
  1263. float scoreReasearchTooFar = 0, scoreTooMany = 0;
  1264.  
  1265.  
  1266. int distance = getDistanceResearch();
  1267. int n = 4;
  1268. int helpStation = 0;
  1269.  
  1270. // try build us a station if it is a good idea*
  1271. if(friendPlaying){
  1272. City currLocation = playerPiece.getLocation();
  1273. playerPiece.setLocation(tmpLocation);
  1274.  
  1275. ArrayList<City> nn = new ArrayList<City>();
  1276. nn.add(currLocation);
  1277. getDistances(nn);
  1278. int distanceToOtherPlayer = playerPiece.getLocation().getDistance();
  1279.  
  1280. int closestStation = getDistanceResearch();
  1281.  
  1282. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  1283. boolean flag = false;
  1284.  
  1285. for(City i : tmpFriendHand)
  1286. if (i.getColour() == "Red")
  1287. redcards++;
  1288. else if (i.getColour() == "Yellow")
  1289. yellowcards++;
  1290. else if (i.getColour() == "Blue")
  1291. bluecards++;
  1292. else
  1293. blackcards++;
  1294.  
  1295. n = 4;
  1296. if (tmpRole == "SCIENTIST")
  1297. n--;
  1298.  
  1299. if(discCity.getColour() == "Red" && (redcards > n ) && ! pandemicBoard.getDisease("Red").cured){
  1300. flag = true;
  1301. }else if(discCity.getColour() == "Yellow" && (yellowcards > n ) && ! pandemicBoard.getDisease("Yellow").cured){
  1302. flag = true;
  1303. }else if(discCity.getColour() == "Blue" && (bluecards > n) && ! pandemicBoard.getDisease("Blue").cured){
  1304. flag = true;
  1305. }else if(discCity.getColour() == "Black" && (blackcards > n ) && ! pandemicBoard.getDisease("Black").cured ){
  1306. flag = true;
  1307. }
  1308.  
  1309. if(distanceToOtherPlayer < 4 && closestStation > 3 && flag){
  1310. for (int i = 0; i < 1000 ; i++) {
  1311. System.out.println("-------------------------------------------");
  1312.  
  1313. }
  1314.  
  1315. helpStation = 1000;
  1316. }
  1317. //if current is within 3 cities distance, consider building
  1318.  
  1319. playerPiece.setLocation(currLocation);
  1320.  
  1321. }
  1322. // Never build when you have reasearch station too near
  1323. if( distance <= 2)
  1324. return -1000;
  1325. n = 4;
  1326. if (playerRole == "SCIENTIST")
  1327. n--;
  1328.  
  1329. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  1330.  
  1331. for(City i : hand)
  1332. if (i.getColour() == "Red")
  1333. redcards++;
  1334. else if (i.getColour() == "Yellow")
  1335. yellowcards++;
  1336. else if (i.getColour() == "Blue")
  1337. bluecards++;
  1338. else
  1339. blackcards++;
  1340.  
  1341. String maxColor;
  1342. int max_color_number = Math.max(Math.max(redcards, yellowcards), Math.max( bluecards, blackcards));
  1343.  
  1344. if( max_color_number == redcards){
  1345. maxColor = "Red";
  1346. }else if(max_color_number == yellowcards){
  1347. maxColor = "Yellow";
  1348. }else if(max_color_number == bluecards){
  1349. maxColor = "Blue";
  1350. }else{
  1351. maxColor = "Black";
  1352. }
  1353.  
  1354. if(discCity.getColour() == maxColor && max_color_number <= n){
  1355. return -1000;
  1356. }
  1357.  
  1358. if(discCity.getNeighbors().size() <= 1) {
  1359. return - 1000;
  1360. }
  1361.  
  1362. if( playerRole == "OPERATIONS_EXPERT")
  1363. scoreOpExp = 4;
  1364. //builder x 50
  1365. else{
  1366. scoreOpExp = 1;
  1367. }
  1368.  
  1369. if (pandemicBoard.getResearchCentre().size() <= 3 && distance > 3 && numOfRounds !=1)
  1370. scoreNoReasearchStations = 1;
  1371. //one research station x 10
  1372.  
  1373. if( distance > 5)
  1374. scoreReasearchTooFar = distance/4;
  1375. //no reasearch near x 10 x
  1376.  
  1377. if (pandemicBoard.getResearchCentre().size() > 3)
  1378. scoreTooMany = (3-pandemicBoard.getResearchCentre().size());
  1379. // too many stations x 40
  1380.  
  1381. return scoreOpExp *(scoreNoReasearchStations*50 + scoreReasearchTooFar*40 + scoreTooMany*20 + helpStation ) ;
  1382. // -40 --- 180
  1383. //TODO callibrate this weight
  1384.  
  1385. // TODO call opponent modelling
  1386.  
  1387. }
  1388.  
  1389.  
  1390. float MAX_DISEASE_SCORE = 65536;
  1391. /**
  1392. Author: @Kallinteris-Andreas
  1393. checks the board evaluate dangers caused by existing diseases (cubes) on the board
  1394. returns: a higher number for a more dangerours board
  1395. (a really high number is returned in cases on game terminating dangers)
  1396. TODO count turns?
  1397. */
  1398. private float scoreDiseases(City c){
  1399. float score = 0;
  1400.  
  1401. //Score based on the danger of outbreaks
  1402. {
  1403. //for (City c : pandemicBoard.get1CubeCities()){
  1404. if (c.getCubeColour(c.getColour()) == 1){
  1405. if (pandemicBoard.infectDeck.getInfectDiscardPile().contains(c)){
  1406. if(epidemics_left() >= 3){
  1407. float expectedTurnsTillNextOutbreak = (float) expectedSizeOfNextDiscardPile2()/ Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw()*2;
  1408. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1409. }
  1410. if (epidemics_left() <= 2){ /*DO NO COUNT SINCE IT CAN NOT GET AN OUTBREAK*/}
  1411. }
  1412. else{
  1413. float expectedTurnsTillNextOutbreak = (float) remaningReshufledInfectCards().size()/Variables.INFECTION_RATE + expectedSizeOfNextDiscardPile()/Variables.INFECTION_RATE + expectedSizeOfNextDiscardPile2()/Variables.INFECTION_RATE;
  1414. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1415. }
  1416. }
  1417. else if (c.getCubeColour(c.getColour()) == 2){
  1418. //for (City c : pandemicBoard.get2CubeCities()){
  1419. if (pandemicBoard.infectDeck.getInfectDiscardPile().contains(c)){
  1420. if(epidemics_left() >= 3){
  1421. float expectedTurnsTillNext2Outbreaks = (float) expectedSizeOfNextDiscardPile3()/Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw()*3;
  1422. score += scoreOutbreak(c) / expectedTurnsTillNext2Outbreaks;
  1423. }
  1424. if(epidemics_left() >= 2){
  1425. float expectedTurnsTillNextOutbreak = (float) expectedSizeOfNextDiscardPile2()/Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw()*2;
  1426. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1427. }
  1428. if (epidemics_left() <= 1){ /*DO NO COUNT SINCE IT CAN NOT GET AN OUTBREAK*/}
  1429. }
  1430. else{
  1431. float expectedTurnsTillNextOutbreak = (float) remaningReshufledInfectCards().size()/Variables.INFECTION_RATE + expectedSizeOfNextDiscardPile()/Variables.INFECTION_RATE;
  1432. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1433. }
  1434. }
  1435. else if (c.getCubeColour(c.getColour()) == 3){
  1436. //for (City c : pandemicBoard.get3CubeCities()){
  1437. if (pandemicBoard.infectDeck.getInfectDiscardPile().contains(c)){
  1438. if(epidemics_left() > 2){
  1439. float expectedTurnsTillNext3Outbreaks = (float) expectedSizeOfNextDiscardPile3()/Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw()*3;
  1440. score += scoreOutbreak(c) / expectedTurnsTillNext3Outbreaks;
  1441. }
  1442. if(epidemics_left() > 1){
  1443. float expectedTurnsTillNext2Outbreaks = (float) expectedSizeOfNextDiscardPile2()/Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw()*2;
  1444. score += scoreOutbreak(c) / expectedTurnsTillNext2Outbreaks;
  1445. }
  1446. if(epidemics_left() > 0){
  1447. float expectedTurnsTillNextOutbreak = (float) expectedSizeOfNextDiscardPile()/Variables.INFECTION_RATE + expectedTurnsTillEpidemicDraw();
  1448. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1449. }
  1450. if (epidemics_left() == 0){ /*DO NO COUNT SINCE IT CAN NOT BE RE-INFECTED*/}
  1451. }
  1452. else{
  1453. float expectedTurnsTillNextOutbreak = (float) remaningReshufledInfectCards().size()/Variables.INFECTION_RATE;
  1454. score += scoreOutbreak(c) / expectedTurnsTillNextOutbreak;
  1455. }
  1456. }
  1457. }
  1458.  
  1459. //Score based on avoiding having 24 cubes in the map
  1460. {
  1461. float PANDEMIC_CUBE_WEIGHT = MAX_DISEASE_SCORE; //2^24
  1462. if (epidemics_left() == 0){
  1463. int redLeft = infectCardsOfColorXRemaining("Red") + pandemicBoard.redCubes;
  1464. int blueLeft = infectCardsOfColorXRemaining("Blue") + pandemicBoard.blueCubes;
  1465. int blackLeft = infectCardsOfColorXRemaining("Black") + pandemicBoard.blackCubes;
  1466. int yellowLeft = infectCardsOfColorXRemaining("Yellow") + pandemicBoard.yellowCubes;
  1467. if (redLeft >= 25)
  1468. score += PANDEMIC_CUBE_WEIGHT*(redLeft-24)/pandemicBoard.infectDeck.getInfectPile().size()*4;
  1469. if (blueLeft >= 25)
  1470. score += PANDEMIC_CUBE_WEIGHT*(blueLeft-24)/pandemicBoard.infectDeck.getInfectPile().size()*4;
  1471. if (blackLeft >= 25)
  1472. score += PANDEMIC_CUBE_WEIGHT*(blackLeft-24)/pandemicBoard.infectDeck.getInfectPile().size()*4;
  1473. if (yellowLeft >= 25)
  1474. score += PANDEMIC_CUBE_WEIGHT*(yellowLeft-24)/pandemicBoard.infectDeck.getInfectPile().size()*4;
  1475. }
  1476. else if (epidemics_left() == 1){
  1477. //very unlikely to happen has been commented out for compute resason
  1478. /*
  1479. int redLeft = infectCardsOfColorXRemaining("Red")/pandemicBoard.infectDeck.getInfectPile().size()/3;
  1480. int blueLeft = infectCardsOfColorXRemaining("Blue") + pandemicBoard.blueCubes;
  1481. int blackLeft = infectCardsOfColorXRemaining("Black") + pandemicBoard.blackCubes;
  1482. int yellowLeft = infectCardsOfColorXRemaining("Yellow") + pandemicBoard.yellowCubes;
  1483. if (pandemicBoard.redCubes > 18)
  1484. score += Math.pow(CUBE_COUNT_WEIGHT, (pandemicBoard.redCubes - 18));
  1485. if (pandemicBoard.blueCubes > 18)
  1486. score += Math.pow(CUBE_COUNT_WEIGHT, (pandemicBoard.blueCubes - 18));
  1487. if (pandemicBoard.yellowCubes > 18)
  1488. score += Math.pow(CUBE_COUNT_WEIGHT, (pandemicBoard.yellowCubes - 18));
  1489. if (pandemicBoard.blackCubes > 18);
  1490. score += Math.pow(CUBE_COUNT_WEIGHT, (pandemicBoard.blackCubes - 18));
  1491. */
  1492. }
  1493. else if (epidemics_left() >= 2){/*actually not possible*/}
  1494. }
  1495.  
  1496. return score;
  1497. }
  1498.  
  1499. /**
  1500. Author: @Kallinteris-Andreas
  1501. Evaluates the danger of a specific outbreak
  1502. Returns: a number indicating that danger level
  1503. */
  1504. private float scoreOutbreak(City c){
  1505. float score = 0;
  1506. final float OUTBREAK_WEIGHT = MAX_DISEASE_SCORE/256;
  1507. int outbreaksLeft = Variables.MAX_NUMBER_OF_OUTBREAK - Variables.OUTBREAK_MARKER;
  1508.  
  1509. //Score based on OUTBREAK_MARKER
  1510. //TODO change scaling (take into account number or turns)
  1511. {
  1512. switch(outbreaksLeft){
  1513. case 1: score += MAX_DISEASE_SCORE; break;
  1514. case 2: score += OUTBREAK_WEIGHT*7; break;
  1515. case 3: score += OUTBREAK_WEIGHT*6; break;
  1516. case 4: score += OUTBREAK_WEIGHT*5; break;
  1517. case 5: score += OUTBREAK_WEIGHT*4; break;
  1518. case 6: score += OUTBREAK_WEIGHT*3; break;
  1519. case 7: score += OUTBREAK_WEIGHT*2; break;
  1520. case 8: score += OUTBREAK_WEIGHT; break;
  1521. }
  1522. }
  1523.  
  1524. //Score based on neighbors
  1525. //Note: we ingnore the case of 4 outbreaks happening in the same city
  1526. {
  1527. for(City neighbor : c.getNeighbors())
  1528. if (neighbor.getColour().equals(c.getColour()))
  1529. switch(neighbor.getMaxCube()){
  1530. case 0: score += 0; break;
  1531. case 1: score += 0; break;
  1532. case 2: score += OUTBREAK_WEIGHT; break;
  1533. case 3: score = MAX_DISEASE_SCORE; break;
  1534. }
  1535. }
  1536.  
  1537. //NOTE: it does take into account cities with 3 cure of a di
  1538. //Note: can be improved at the cost of computation cost
  1539. {
  1540. if (c.getCubeColour(c.getColour()) == 3)
  1541. if (c.getColour().equals("Red"))
  1542. if (c.getNeighbors().size() + pandemicBoard.redCubes > 24)
  1543. score += MAX_DISEASE_SCORE;
  1544. else if (c.getColour().equals("Blue"))
  1545. if (c.getNeighbors().size() + pandemicBoard.blueCubes > 24)
  1546. score += MAX_DISEASE_SCORE;
  1547. else if (c.getColour().equals("Black"))
  1548. if (c.getNeighbors().size() + pandemicBoard.blackCubes > 24)
  1549. score += MAX_DISEASE_SCORE;
  1550. else if (c.getColour().equals("Yellow"))
  1551. if (c.getNeighbors().size() + pandemicBoard.yellowCubes > 24)
  1552. score += MAX_DISEASE_SCORE;
  1553. }
  1554.  
  1555. return score;
  1556. }
  1557.  
  1558.  
  1559.  
  1560.  
  1561. private float flightScoreCalculator (City discCity){
  1562.  
  1563. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  1564. int n = 4;
  1565. final float DISCARD_WEIGHT = 5;
  1566.  
  1567. if(friendPlaying){
  1568. if (tmpRole == "SCIENTIST")
  1569. n--;
  1570.  
  1571. for(City i : tmpFriendHand)
  1572. if (i.getColour() == "Red")
  1573. redcards++;
  1574. else if (i.getColour() == "Yellow")
  1575. yellowcards++;
  1576. else if (i.getColour() == "Blue")
  1577. bluecards++;
  1578. else
  1579. blackcards++;
  1580.  
  1581. if(discCity.getColour() == "Red" && (redcards > n ) ){
  1582. return DISCARD_WEIGHT;
  1583. }else if(discCity.getColour() == "Yellow" && (yellowcards > n )){
  1584. return DISCARD_WEIGHT;
  1585. }else if(discCity.getColour() == "Blue" && (bluecards > n)){
  1586. return DISCARD_WEIGHT;
  1587. }else if(discCity.getColour() == "Black" && (blackcards > n ) ){
  1588. return DISCARD_WEIGHT;
  1589. }
  1590. }
  1591.  
  1592. for(int i = 0; i<4 ;i++){
  1593. if(pandemicBoard.diseases.get(i).cured && (discCity.getColour() == pandemicBoard.diseases.get(i).getColour())){
  1594. return DISCARD_WEIGHT;
  1595. }
  1596. }
  1597. n = 4;
  1598. if (playerRole == "SCIENTIST")
  1599. n--;
  1600.  
  1601. yellowcards = 0;
  1602. blackcards = 0;
  1603. redcards = 0;
  1604. bluecards = 0;
  1605.  
  1606. for(City i : hand)
  1607. if (i.getColour() == "Red")
  1608. redcards++;
  1609. else if (i.getColour() == "Yellow")
  1610. yellowcards++;
  1611. else if (i.getColour() == "Blue")
  1612. bluecards++;
  1613. else
  1614. blackcards++;
  1615.  
  1616.  
  1617.  
  1618. String maxColor;
  1619. int max_color_number = Math.max(Math.max(redcards, yellowcards), Math.max( bluecards, blackcards));
  1620.  
  1621. if( max_color_number == redcards){
  1622. maxColor = "Red";
  1623. }else if(max_color_number == yellowcards){
  1624. maxColor = "Yellow";
  1625. }else if(max_color_number == bluecards){
  1626. maxColor = "Blue";
  1627. }else{
  1628. maxColor = "Black";
  1629. }
  1630.  
  1631. if(discCity.getColour() == maxColor && max_color_number <= n){
  1632. return -1000;
  1633. }
  1634.  
  1635. if(discCity.getColour() == "Red" && (redcards > n ) ){
  1636. return DISCARD_WEIGHT;
  1637. }else if(discCity.getColour() == "Yellow" && (yellowcards > n )){
  1638. return DISCARD_WEIGHT;
  1639. }else if(discCity.getColour() == "Blue" && (bluecards > n)){
  1640. return DISCARD_WEIGHT;
  1641. }else if(discCity.getColour() == "Black" && (blackcards > n ) ){
  1642. return DISCARD_WEIGHT;
  1643. }
  1644.  
  1645. // if(discCity.getColour() == "Red" && (redcards > n || redcards <n-2) && numOfRounds > 2){
  1646. // return -50;
  1647. // }else if(discCity.getColour() == "Yellow" && (yellowcards > n || yellowcards <n-2) && numOfRounds > 2){
  1648. // return -50;
  1649. // }else if(discCity.getColour() == "Blue" && (bluecards > n || bluecards <n-2 ) && numOfRounds > 2){
  1650. // return -50;
  1651. // }else if(discCity.getColour() == "Black" && (blackcards > n || blackcards <n-2 ) && numOfRounds > 2){
  1652. // return -50;
  1653. // }
  1654.  
  1655. return -1000;
  1656. }
  1657.  
  1658.  
  1659. /**
  1660. TODO MAKE SOMETHING THAT MAKES SENSE
  1661. */
  1662. private float scoreQuarantineSpecialist (City curCity){
  1663. int curInfectionLevel = 0;
  1664. int infectionWeight = 3;
  1665. float score = 0;
  1666. for (City c : curCity.getNeighbors()){
  1667. curInfectionLevel = 0;
  1668. for (String i : possibleColour) {
  1669. curInfectionLevel += c.getCubeColour(i);
  1670. }
  1671.  
  1672. if(curInfectionLevel == 1){
  1673. score +=1 * infectionWeight;
  1674. }else if(curInfectionLevel == 2){
  1675. score +=3 * infectionWeight;
  1676. }else if(curInfectionLevel == 3){
  1677. score +=10 * infectionWeight;
  1678. }else if(curInfectionLevel == 0){
  1679. score +=0;
  1680. }else{
  1681. System.out.println("Error in cubes");
  1682. System.exit(1);
  1683. }
  1684.  
  1685. }
  1686. return score;
  1687.  
  1688. }
  1689.  
  1690. /** Author: @kallinteris-Andreas
  1691. this function simulates the results of the suggested actions and
  1692. returns: the a score indicating how good those actions were
  1693. */
  1694. @SuppressWarnings("unused")
  1695. private float scoreSuggestion(ArrayList<Action> suggestion){
  1696.  
  1697. //System.out.println("Location "+ playerPiece.getLocation().getName());
  1698. City playerCity = playerPiece.getLocation();
  1699. float temp_weight = 0,tmp_score_after,tmp_score_before;
  1700.  
  1701. LinkedList<City> treats = new LinkedList<City>();
  1702. LinkedList<Integer> numberOfTreats = new LinkedList<Integer>();
  1703. LinkedList<String> colourOfTreat = new LinkedList<String>();
  1704.  
  1705. for (Action act : suggestion){
  1706.  
  1707. //System.out.println(act);
  1708. if(act instanceof driveCity){
  1709.  
  1710. if(!driveCity(((Pandemic.actions.driveCity) act).getMoveFrom(),((Pandemic.actions.driveCity) act).getMoveTo())){
  1711. System.out.println("driveCity error suggestion");
  1712. System.exit(1);
  1713. }
  1714.  
  1715. }else if(act instanceof charterFlight){
  1716. temp_weight += flightScoreCalculator(playerPiece.getLocation());
  1717.  
  1718.  
  1719. if(! charterFlight(playerPiece.getLocation(), ((charterFlight) act).getMoveTo())) {
  1720. System.out.println("Charter flight error suggestion");
  1721. System.exit(0);
  1722. }
  1723.  
  1724. }else if(act instanceof directFlight){
  1725. temp_weight += flightScoreCalculator(((directFlight) act).getMoveTo());
  1726.  
  1727.  
  1728. if(!directFlight(playerPiece.getLocation(), ((Pandemic.actions.directFlight) act).getMoveTo())){
  1729. System.out.println("Direct flight error suggestion");
  1730. System.exit(1);
  1731. }
  1732.  
  1733. }else if(act instanceof buildResearchStation){
  1734. temp_weight += score_ResearchStation(((buildResearchStation) act).getCityToResearchStation());
  1735.  
  1736. if(!buildResearchStation()){
  1737. System.out.println("buildResearchStation error suggestion");
  1738. System.exit(1);
  1739. }
  1740.  
  1741.  
  1742.  
  1743. }else if(act instanceof discoverCure){
  1744. temp_weight += 100000;
  1745. if(!discoverCure(playerPiece.getLocation(), ((Pandemic.actions.discoverCure) act).getColorOfDisease())){
  1746. System.out.println("discoverCure error suggestion");
  1747. System.exit(1);
  1748. }
  1749.  
  1750. }else if(act instanceof shuttleFlight){
  1751. if(!shuttleFlight(((Pandemic.actions.shuttleFlight) act).getMoveFrom(), ((Pandemic.actions.shuttleFlight) act).getMoveTo())){
  1752. System.out.println("shuttleFlight error suggestion");
  1753. System.exit(1);
  1754. }
  1755.  
  1756. }else if(act instanceof treatDisease){
  1757.  
  1758. treats.add(((treatDisease) act).getLocation());
  1759.  
  1760. if(playerRole == "MEDIC") {
  1761. numberOfTreats.add(((treatDisease) act).getLocation().getCubeColour(((treatDisease) act).getColour()));
  1762. }else {
  1763. numberOfTreats.add(1);
  1764. }
  1765. colourOfTreat.add(((treatDisease) act).getColour());
  1766.  
  1767. //System.out.println("Location "+ playerPiece.getLocation().getName());
  1768.  
  1769. tmp_score_before = scoreDiseases(((treatDisease) act).getLocation());
  1770. if(!treatDisease(playerPiece.getLocation(), ((Pandemic.actions.treatDisease) act).getColour())){
  1771. System.out.println("treatDisease error suggestion");
  1772. System.exit(1);
  1773. }
  1774.  
  1775. tmp_score_after = scoreDiseases(((treatDisease) act).getLocation());
  1776.  
  1777. temp_weight += tmp_score_before - tmp_score_after;
  1778.  
  1779. }else{
  1780. //not supposed to reach this
  1781. System.out.println("Howw?????");
  1782. System.exit(1);
  1783. }
  1784. }
  1785. System.out.println("---------------------------");
  1786.  
  1787. //Evaluate board State
  1788.  
  1789. int yellowcards = 0, blackcards = 0, redcards = 0, bluecards = 0;
  1790. boolean flag = false;
  1791.  
  1792. for(City i : hand)
  1793. if (i.getColour() == "Red")
  1794. redcards++;
  1795. else if (i.getColour() == "Yellow")
  1796. yellowcards++;
  1797. else if (i.getColour() == "Blue")
  1798. bluecards++;
  1799. else
  1800. blackcards++;
  1801.  
  1802. int n = 4;
  1803. if (playerRole == "SCIENTIST")
  1804. n--;
  1805.  
  1806. if(redcards >= n-1 && ! pandemicBoard.getDisease("Red").cured){
  1807. flag = true;
  1808. }else if(yellowcards >= n-1 && ! pandemicBoard.getDisease("Yellow").cured){
  1809. flag = true;
  1810. }else if(bluecards >= n-1 && ! pandemicBoard.getDisease("Blue").cured){
  1811. flag = true;
  1812. }else if(blackcards >= n-1 && ! pandemicBoard.getDisease("Black").cured ){
  1813. flag = true;
  1814. }
  1815.  
  1816. //score
  1817. if(flag && getDistanceResearch() <=3){
  1818. if(numOfRounds > 4){
  1819. temp_weight += 300;
  1820. //System.out.println("+++\n\n\n\n\n\n\n\n\n\n\n");
  1821. }else{
  1822. temp_weight += 30;
  1823. }
  1824. }
  1825.  
  1826.  
  1827. if(playerRole == "QUARANTINE_SPECIALIST") {
  1828. temp_weight += scoreQuarantineSpecialist(playerPiece.getLocation()); //function to score his standing position specifically
  1829. }
  1830.  
  1831. //Revert cubes
  1832.  
  1833. for(int i =0; i<treats.size();i++) {
  1834.  
  1835. for(int j=0;j<numberOfTreats.get(i);j++)
  1836. treats.get(i).addCube(colourOfTreat.get(i));
  1837. }
  1838.  
  1839.  
  1840. return temp_weight;
  1841. }
  1842.  
  1843. //UTILITY FUNCTIONS
  1844. //UTILITY FUNCTIONS
  1845. //UTILITY FUNCTIONS
  1846. /** Author: @kallinteris-Andreas
  1847. returns: TRUE if there are epemic cards left in the deck
  1848. */
  1849. // private boolean epidemic_left(){
  1850. // return epidemics_left() != 0;
  1851. // }
  1852.  
  1853. /** Author: @kallinteris-Andreas
  1854. returns: the number of epemic cards that are left in the player deck
  1855. */
  1856. private int epidemics_left(){
  1857. int t = 4;
  1858. for (Object o : pandemicBoard.playerDeck.getPlayerDiscardPile())
  1859. if(o.equals(true))
  1860. t--;
  1861. return t;
  1862. }
  1863.  
  1864. /**
  1865. Note:assumes that there are epidemics lefts in the deck
  1866. returns: the expected number of turns till it an epidemic card is drawn
  1867. */
  1868. private int expectedTurnsTillEpidemicDraw(){
  1869. return pandemicBoard.playerDeck.getPlayerPile().size() / (2* epidemics_left()) ;
  1870. }
  1871.  
  1872. /** Author: @kallinteris-Andreas
  1873. returns: the expected size of the next discard pile (after an epidemic card is drawn)
  1874. */
  1875. private int expectedSizeOfNextDiscardPile(){
  1876. return expectedTurnsTillEpidemicDraw() * Variables.INFECTION_RATE + pandemicBoard.infectDeck.getInfectDiscardPile().size();
  1877. }
  1878.  
  1879. private int expectedSizeOfNextDiscardPile2(){
  1880. return expectedSizeOfNextDiscardPile() + expectedTurnsTillEpidemicDraw()*Variables.INFECTION_RATE;
  1881. }
  1882. private int expectedSizeOfNextDiscardPile3(){
  1883. return expectedSizeOfNextDiscardPile2() + expectedTurnsTillEpidemicDraw()*Variables.INFECTION_RATE;
  1884. }
  1885. /** Author: @kallinteris-Andreas
  1886. returns: the expected size of the next discard pile (after an epidemic card is drawn)
  1887. */
  1888. private ArrayList<City> remaningReshufledInfectCards(){
  1889. ArrayList<City> remainingCards = new ArrayList<>();
  1890.  
  1891. for (City c : pandemicBoard.infectDeck.getInfectDiscardPileBeforeEpidemic())
  1892. if (!pandemicBoard.infectDeck.getInfectDiscardPile().contains(c))
  1893. remainingCards.add(c);
  1894. return remainingCards;
  1895. }
  1896.  
  1897. /** Author: @kallinteris-Andreas
  1898. returns: the number of cards in the infect deck of color X
  1899. */
  1900. private int infectCardsOfColorXRemaining(String X){
  1901. int count = 12;
  1902. for (City c : pandemicBoard.infectDeck.getInfectDiscardPile())
  1903. if (c.getColour().equals(X))
  1904. count--;
  1905. return count;
  1906. }
  1907. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement