Skip to content

Commit

Permalink
Merge pull request #25 from san089/haifeng
Browse files Browse the repository at this point in the history
Add method description for java doc
  • Loading branch information
san089 authored Dec 4, 2019
2 parents ba47648 + 2ecb75b commit b8e587b
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 50 deletions.
82 changes: 53 additions & 29 deletions src/com/concordia/riskgame/model/Modules/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,6 @@ public Player(int playerIndex, String playerName) {
this.strategy = new Human();
}

public int getNumOfInfCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.INFANTRY) {
n++;
}
}
return n;
}

public int getNumOfCavCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.CAVALRY) {
n++;
}
}
return n;
}
public int getNumOfArtCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.ARTILLERY) {
n++;
}
}
return n;
}

public void setPlayerIndex(int playerIndex) {
this.playerIndex = playerIndex;
}
Expand Down Expand Up @@ -250,6 +221,53 @@ public void attack(String command) {

}

/**
* To get player's number of infantry card
* @return
*/
public int getNumOfInfCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.INFANTRY) {
n++;
}
}
return n;
}

/**
* To get player's number of cavalery card
* @return
*/
public int getNumOfCavCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.CAVALRY) {
n++;
}
}
return n;
}

/**
* To get number of art cards
* @return
*/
public int getNumOfArtCard() {
int n = 0;
for (Card card : cardsOwned) {
if (card == Card.ARTILLERY) {
n++;
}
}
return n;
}

/**
* check defending command
* @param command
*/

public void defendCommand(String command) {
if (!defendCommandInput) {
System.out.println("Not defending time");
Expand Down Expand Up @@ -554,6 +572,12 @@ private void autoAttack() {

}

/**
* Player do fortification
* @param command
* @return
*/

public boolean fortifyArmy(String command) {
String[] commands = command.split(" ");
fromCountry = gameMap.searchCountry(commands[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import java.io.Serializable;
import java.util.*;

/**
* This class is one of the player's strategy, aggressive player .
*
*/

public class Aggressive implements Strategy,Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
private String strategyName = "Aggressive";
public String ANSI_BLUE = "\u001B[34m";
//private Gameplay gameplay =Gameplay.getInstance();
private Country strongestFrontCountry;

public String getColor() {
Expand All @@ -29,8 +30,11 @@ public String getStrategyName() {
return strategyName;
}

/**
* Aggressive player do card exchange once cards are available.
*/

public void doCardExchange(){
// gameplay =Gameplay.getInstance();
try {

System.out.println("Bot Executing Command : " + "exchangecards 3 0 0");
Expand All @@ -50,6 +54,10 @@ public void doCardExchange(){

}

/**
* Aggressive player do reinforcement in reinforce phase.
*/

public void doReinforcement(){
try {
strongestFrontCountry = getStrongestFrontCountry();
Expand All @@ -63,6 +71,10 @@ public void doReinforcement(){

}

/**
* Aggressive player do attack in attack phase.
*/

public void doAttack(){
try {
for (String neighbor : strongestFrontCountry.getListOfNeighbours()) {
Expand Down Expand Up @@ -94,6 +106,11 @@ public void doAttack(){
}
}

/**
* Aggressive player do fortification in fortify phase. First find the player's front battle line country, check the
* most reinforce they can get, and where they can get, then find the best country, get the best neighbor.
*/

public void doFortification() {
Map<Country, Integer> frontBattleCountry = new HashMap<>();
HashMap<Country, Country> frontBattleCountryNeighbor = new HashMap<>();
Expand All @@ -113,7 +130,7 @@ public void doFortification() {
frontBattleCountry.put(country, most + country.getNoOfArmiesPresent());
frontBattleCountryNeighbor.put(country, bestNeighbor);
}

//find the best country
for (Country country : frontBattleCountry.keySet()) {
int m = frontBattleCountry.get(country);
int n = frontBattleCountry.get(bestCountry);
Expand Down Expand Up @@ -142,6 +159,10 @@ public void doFortification() {
}
}

/**
* This function is to find the strongest country to do attack
* @return
*/
public Country getStrongestFrontCountry(){
Country strongest = frontBattleLine().get(0);
for(Country c : frontBattleLine()){
Expand All @@ -152,6 +173,10 @@ public Country getStrongestFrontCountry(){
return strongest;
}

/**
* this country find all the available attack country
* @return front line country arraylist
*/
public ArrayList<Country> frontBattleLine() {
ArrayList<Country> frontBattleCountry = new ArrayList<>();
for (String country : Gameplay.getInstance().getCurrentPlayer().getCountriesOwned()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

import java.io.Serializable;
import java.util.ArrayList;

/**
* This class is one of the player's strategy, Benevolent player .
*
*/
public class Benevolent implements Strategy,Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
private String strategyName = "Benevolent";
public String ANSI_YELLOW = "\u001B[33m";
// Gameplay gameplay = Gameplay.getInstance();

public String getColor() {
return ANSI_YELLOW;
Expand All @@ -27,8 +26,10 @@ public String getStrategyName() {
return strategyName;
}

/**
* Benevolent player do card exchange.
*/
public void doCardExchange(){
// gameplay =Gameplay.getInstance();
try {

System.out.println("Bot Executing Command : " + "exchangecards 3 0 0");
Expand All @@ -47,8 +48,11 @@ public void doCardExchange(){
}
}

/**
* Benevolent player do reinforce
*/

public void doReinforcement(){
// gameplay =Gameplay.getInstance();
int armies_available = Gameplay.getInstance().getCurrentPlayer().getArmyCount();
String countryName = getWeakestCountry();
String reinforceCommand;
Expand All @@ -69,6 +73,10 @@ public void doReinforcement(){
}
}

/**
* Benevolent player do attack, just skip attack phase
*/

public void doAttack(){
System.out.println("Benevolent Bot Does not attack.");
try{
Expand All @@ -81,6 +89,9 @@ public void doAttack(){

}

/**
* Benevolent player do fortification
*/
public void doFortification() {
int armies_available = Gameplay.getInstance().getCurrentPlayer().getArmyCount();
String countryName = getWeakestCountry();
Expand All @@ -104,6 +115,11 @@ public void doFortification() {
}
}

/**
* Benevolent player get the weakest country to fortify
* @return weakest country's name
*/

public String getWeakestCountry(){
Country weakest = Gameplay.getInstance().getSelectedMap().getOwnedCountries(Gameplay.getInstance().getCurrentPlayer().getPlayerName()).get(0);
ArrayList<Country> countryOwnedList = Gameplay.getInstance().getSelectedMap().getOwnedCountries(Gameplay.getInstance().getCurrentPlayer().getPlayerName());
Expand Down
20 changes: 17 additions & 3 deletions src/com/concordia/riskgame/model/Modules/Stratigies/Cheater.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.ArrayList;
import java.util.List;

/**
* Cheater player's turn
*/
public class Cheater implements Strategy,Serializable {

/**
Expand All @@ -17,7 +20,6 @@ public class Cheater implements Strategy,Serializable {
private static final long serialVersionUID = 1L;
private String strategyName = "Cheater";
public String ANSI_PURPLE = "\u001B[35m";
// Gameplay gameplay = Gameplay.getInstance();

public String getColor() {
return ANSI_PURPLE;
Expand All @@ -29,9 +31,10 @@ public String getStrategyName() {
return strategyName;
}

/**
* Cheater do card exchange
*/
public void doCardExchange(){
// this.gameplay = Gameplay.getInstance(); //For updating the class gameplay object when we load a saved game.

try {
System.out.println("Bot Executing Command : " + "exchangecards 3 0 0");
CommandController.parseCommand("exchangecards 3 0 0");
Expand All @@ -49,6 +52,10 @@ public void doCardExchange(){
}
}

/**
* cheater do reinforcement
*/

public void doReinforcement(){

Country tempCountry = null;
Expand Down Expand Up @@ -86,6 +93,9 @@ public void doReinforcement(){
}
}

/**
* cheater do attack
*/
public void doAttack(){
System.out.println(getStrategyName() + " bot playing reinforcement phase.");
ArrayList<Country> ownedCountries = Gameplay.getInstance().getSelectedMap().getOwnedCountries(Gameplay.getInstance().getCurrentPlayer().getPlayerName());
Expand Down Expand Up @@ -138,6 +148,10 @@ public void doAttack(){
}
}

/**
* cheater do fortification
*/

public void doFortification() {

if(Gameplay.getInstance().getCurrentPlayer().isWinner()){
Expand Down
Loading

0 comments on commit b8e587b

Please sign in to comment.