blob: e484749abc5544235142ef8561beb1dad0d0e5ad (
plain)
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
100
101
102
103
|
package ch.asynk.tankontank.game;
import java.util.Random;
import ch.asynk.tankontank.TankOnTank;
import ch.asynk.tankontank.engine.Pawn;
public class Player extends ch.asynk.tankontank.engine.Player
{
private static final float MOVE_TIME = 0.4f;
private static Random rand = new Random();
private int turn;
private int apSpent;
private int actionPoints;
public Player(final TankOnTank game, Army army, int n)
{
super(army, n);
this.turn = 0;
this.actionPoints = 0;
}
public String toString()
{
return faction + " AP: " + actionPoints +
" units:" + units.size() + " casualties:" + casualties.size();
}
public int getAp()
{
return (apSpent + 1);
}
public int getTurn()
{
return turn;
}
public boolean apExhausted()
{
return (apSpent == actionPoints);
}
public void burnDownOneAp()
{
apSpent += 1;
if (apSpent > actionPoints) System.err.println("ERROR: spent too much AP, please report");
}
@Override
public void turnEnd()
{
}
@Override
public void turnStart()
{
turn += 1;
for (Pawn pawn : units)
pawn.reset();
computeActionPoints();
}
public int d6()
{
return rand.nextInt(6) + 1;
}
private void computeActionPoints()
{
this.actionPoints = 2;
if (d6() > 2) {
this.actionPoints += 1;
if (d6() > 3)
this.actionPoints += 1;
}
apSpent = 0;
}
public boolean canPromote(Pawn pawn)
{
if (pawn.isHq()) return false;
for (Pawn p: casualties)
if (p.isHqOf(pawn)) return true;
return false;
}
public Unit promote(Unit unit)
{
for (Pawn p: casualties) {
if (p.isHqOf(unit)) {
units.remove(unit);
casualties.add(unit);
units.add(p);
casualties.remove(p);
return (Unit) p;
}
}
return null;
}
}
|