-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBot.java
99 lines (79 loc) · 2.36 KB
/
Bot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.ArrayList;
import java.util.Random;
/**
* This class is a simple bot that play insted player
*
*
* @author Mohammad Mahdi Malmasi
* @version 0.2.0
*/
public class Bot extends Player
{
/* Constructor */
/**
* Creat a new Bot
* @param num : the number of the bot
*/
public Bot(int num)
{
super("Bot"+num, ""+num);
}
/**
* This method is a kind of main method for bot
* It makes bot decision
*
*
* @param players : the players of the game
* @param botIndex : the index of the bot in the player arraylist
*
* @return the bot choosen card
*/
public Card playTurn(ArrayList<Player> players, ArrayList<Card> penaltyCards, int botIndex)
{
Card botChoosenCard = null;
for (int n = 0; n < super.getPlayerCards().size(); n++)
{
botChoosenCard = super.getPlayerCards().get(n);
if (Rules.checkChoose(botChoosenCard, this))
{
this.getPlayerCards().remove(botChoosenCard);
score -= botChoosenCard.getCardScore();
break;
}
}
// the cases that bot must choose a color
if (botChoosenCard instanceof WildCard || botChoosenCard instanceof WildDrawCard)
{
Random rand = new Random();
switch (rand.nextInt(4)+1)
{
case 1:
Rules.applyChoose(botChoosenCard, Color.RED);
break;
case 2:
Rules.applyChoose(botChoosenCard, Color.YELLOW);
break;
case 3:
Rules.applyChoose(botChoosenCard, Color.GREEN);
break;
case 4:
Rules.applyChoose(botChoosenCard, Color.BLUE);
break;
}
}
else
Rules.applyChoose(botChoosenCard, botChoosenCard.getCardColor());
// wild draw case
if (botChoosenCard instanceof WildDrawCard)
{
int index = (botIndex+1)%players.size();
int n = penaltyCards.size();
for (; n > 0; n--)
{
players.get(index).addCard(penaltyCards.get(0));;
penaltyCards.remove(0);
}
}
return botChoosenCard;
}
}