class Player public int m_pid public Point m_pos public int m_bombs pu

  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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
class Player
{
public int m_pid;
public Point m_pos;
public int m_bombs;
public int m_str;
public int m_speed;
public boolean m_infict;
public int m_control_sum;
// bonuses are saved from 0 till 2 in the next way: "b" "v" "f"
public int m_good_bonus[] = {0x40,0x20,0x10};
// bonuses are save from 0 till 3 in the next way: "r" "s" "u" "o"
public int m_bad_bonus[] ={0x8,0x4,0x2,0x1};
// first 7 bits contain bonuses.The highest three bits are positive bonuses =)
// the lower ones are negative;
public char m_good[] = {'b','v','f' };
public char m_bad[] = {'r','s','u','o'};
public int m_bonuses;
// delete mask. first 3 elements belong to positive bonuses and others to negative.
// for 0 till 6 they go : "b" "v" "f" "r" "s" "u" "o"
public int m_del_mask[] = {0x3F,0x5F,0x6F,0x77,0x7B,0x7D,0x7E};
public Player(int _pid, Point _pos, int _bombs, int _bombsStrength, int _speed, boolean _isInfected) {
m_pid = _pid; m_pos = _pos; m_bombs = _bombs; m_str = _bombsStrength; m_speed = _speed; m_infict = _isInfected;
}
public Player()
{
}
public void controlSumUpdate()
{
m_control_sum = (m_bombs <<8) + (m_str <<4) + m_speed;
}
// adds bitmask by char
public void addBonus (char _b )
{
switch (_b)
{
case 'b':
m_bonuses = m_bonuses | m_good_bonus[0];
break;
case 'v':
m_bonuses = m_bonuses | m_good_bonus[1];
break;
case 'f':
m_bonuses = m_bonuses | m_good_bonus[2];
break;
case 'r':
m_bonuses = m_bonuses | m_bad_bonus[0];
m_infict = true;
break;
case 's':
m_bonuses = m_bonuses | m_bad_bonus[1];
m_infict = true;
break;
case 'u':
m_bonuses = m_bonuses | m_bad_bonus[2];
m_infict = true;
break;
case 'o':
m_bonuses = m_bonuses | m_bad_bonus[3];
m_infict = true;
break;
}
}
//deletes bitmask by char
public void delBonus (char _b )
{
m_infict = true;
switch (_b)
{
case 'b':
m_bonuses = m_bonuses & m_del_mask[0];
break;
case 'v':
m_bonuses = m_bonuses & m_del_mask[1];
break;
case 'f':
m_bonuses = m_bonuses & m_del_mask[2];
break;
case 'r':
m_bonuses = m_bonuses & m_del_mask[3];
m_infict = false;
break;
case 's':
m_bonuses = m_bonuses & m_del_mask[4];
m_infict = false;
break;
case 'u':
m_bonuses = m_bonuses & m_del_mask[5];
m_infict = false;
break;
case 'o':
m_bonuses = m_bonuses & m_del_mask[6];
m_infict = false;
break;
}
}
public void randomAdd()
{
int new_control_sum = (m_bombs <<8) + (m_str <<4) + m_speed;
new_control_sum = (m_control_sum^new_control_sum);
if (new_control_sum == 0)
{
//TODO: check for bonuses 'r' and 'u' should be resolved in some way...
}
else if ((new_control_sum>>4) == 0)
{
if(m_infict)
{
addBonus('s');
}
else
{
addBonus('v');
}
}
else if ((new_control_sum >>4) == 0)
{
addBonus('f');
}
else
{
if(m_infict)
{
addBonus('o');
}
else
{
addBonus('b');
}
}
controlSumUpdate();
}
}