Skip to content

Commit ca5307d

Browse files
committed
2 parents 9ea0d89 + b1cd004 commit ca5307d

File tree

11 files changed

+547
-90
lines changed

11 files changed

+547
-90
lines changed
14 Bytes
Binary file not shown.

__pycache__/scriptred.cpython-310.pyc

-3 Bytes
Binary file not shown.

docs/Game.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,29 @@ At the start of the team, both of the two teams are provided with `X` Rum, `X` W
3232
There are 3 resources that you will find scattered the map. Resources are collected by a team when their pirates move onto tiles that contain them. These resources are **shared commonly by the whole team**, and play different roles in the game:
3333

3434
### Rum
35-
Rum is used to spawn more pirates at the team's deploy point. It is used automatically at collection, and each pirate costs `50` Rum.
35+
Rum is used to spawn more pirates at the team's deploy point. It is used automatically on collection, and each pirate costs `50` Rum.
3636

3737
Rum is never replenished, and is thus a limited resource on the Map.
3838

3939
### Wood
4040
Wood is used to build walls around islands the team is occupying. Building walls costs `50` Wood, and the team must decide when to use this resource.
4141

42+
When walls are built around an island, pirates within the walls cannot leave the island and pirates from outside cannot enter the island. A team can build walls around an island only if there are no enemy pirates in that island.
43+
44+
Walls around an island are automatically dissolved after `50` timeframes.
45+
46+
Each island also has a cooldown period of `35` timeframes, during which walls cannot be built around it.
47+
4248
Wood is never replenished, and is thus a limited resource on the Map.
4349

4450
### Gunpowder
4551
Gunpowder is an important resource used in battles, when pirates come in contact with each other <u>i.e.</u> move onto the same tile.
4652

47-
If the pirate's team has atleast `100` Gunpowder, then the pirate destroys the enemy pirate. j
53+
If the pirate's team has atleast `100` Gunpowder, then the pirate destroys the enemy pirate.
4854

49-
Gunpowder is periodically replenished on the Map if its amount falls below a certain threshold.
55+
More specifically, if both teams have atleast `100` gunpowder, both pirates are killed. If only one team has atleast `100` gunpowder, only the enemy pirate is killed. If both teams have less than `100` gunpowder, neither pirate is killed.
5056

51-
## Base
52-
53-
The Base has the power to create robots and providing them with a signal while doing so. Apart from that, every robot could put up a signal of its own, which could only be read and interpreted at its parent base, to decide on future strategy.
54-
55-
It could also deploy virus, if it gets surrounded by enemy bots.
57+
Gunpowder is periodically replenished on the Map if its amount falls below a certain threshold.
5658

5759
## Pirates
5860

@@ -62,12 +64,12 @@ The primary action that a pirate can perform is to **move**, and to decide where
6264

6365
Each pirate occupies exactly one tile at any time, and any tile that has one or more pirates from a team will have a ship displayed on it.
6466

65-
## 2. Communication Between Base and Robots
67+
## Communication Between Team and Pirates
6668

6769
There are three types of Signals in the game:
6870

69-
1. Those passed onto Robots, when they are created (by the Base Function)
70-
2. Those which are put up by the base and could be read by all of its robots
71-
3. Those which are put up by robots and can be read by the parent base
71+
1. Those passed onto Robots, when they are created (by the Team)
72+
2. Those which are put up by the team and can be read by all of its pirates
73+
3. Those which are put up by pirates and can be read by the parent team
7274

73-
These could be used to co-ordinate movements and strategise attacks/defence.
75+
These can be used to co-ordinate movements and strategize attacks/defence.

engine/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
from tkinter import messagebox
1616
import traceback
1717

18-
# random.seed(5)
19-
2018
status_to_sea = [SEA_DARKBLUE, SEA_BLUE, SEA_RED]
2119
status_to_color = [BLUE, LIGHT_GRAY, RED]
2220
status_to_team = ["Blue", "Neutral", "Red"]

engine/team.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def __init__(self, screen, type, __pirate_list, __pirate_map, game, base):
1111
self.__myGame = game
1212
self.__type = type
1313
self.__rum = 400
14-
self.__gunpowder = 1000
15-
self.__wood = 300
14+
self.__gunpowder = 500
15+
self.__wood = 150
1616
self.__flag1 = None
1717
self.__flag2 = None
1818
self.__flag3 = None
@@ -24,7 +24,7 @@ def __init__(self, screen, type, __pirate_list, __pirate_map, game, base):
2424
self.__signal = ""
2525
self.__created_count = 0
2626

27-
for _ in range(80):
27+
for _ in range(8):
2828
x = random.randint(0, 39)
2929
y = random.randint(0, 39)
3030
self.create_Pirate(base[0] * 20, base[1] * 20, "")
@@ -145,21 +145,21 @@ def addResource(self, type, x, y, frac):
145145
y = y * 20
146146

147147
if type == -1:
148-
self.__rum += 100 * frac
148+
self.__rum += 20 * frac
149149

150150
for i in self.__myGame._Game__rum:
151151
if i.rect == (x, y, 20, 20):
152152

153153
self.__myGame._Game__rum.remove(i)
154154
break
155155
elif type == -2:
156-
self.__gunpowder += 10 * frac
156+
self.__gunpowder += 50 * frac
157157
for i in self.__myGame._Game__gunpowder:
158158
if i.rect == (x, y, 20, 20):
159159
self.__myGame._Game__gunpowder.remove(i)
160160
break
161161
elif type == -3:
162-
self.__wood += 100 * frac
162+
self.__wood += 25 * frac
163163
for i in self.__myGame._Game__wood:
164164
if i.rect == (x, y, 20, 20):
165165
self.__myGame._Game__wood.remove(i)

sample_scripts/sample1.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import random
2+
import math
3+
4+
name = "sample1"
5+
6+
7+
def moveTo(x, y, Pirate):
8+
position = Pirate.getPosition()
9+
if position[0] == x and position[1] == y:
10+
return 0
11+
if position[0] == x:
12+
return (position[1] < y) * 2 + 1
13+
if position[1] == y:
14+
return (position[0] > x) * 2 + 2
15+
if random.randint(1, 2) == 1:
16+
return (position[0] > x) * 2 + 2
17+
else:
18+
return (position[1] < y) * 2 + 1
19+
20+
21+
def ActPirate(pirate):
22+
up = pirate.investigate_up()
23+
down = pirate.investigate_down()
24+
left = pirate.investigate_left()
25+
right = pirate.investigate_right()
26+
x, y = pirate.getPosition()
27+
pirate.setSignal("")
28+
s = pirate.trackPlayers()
29+
30+
if (
31+
(up == "island1" and s[0] != "myCaptured")
32+
or (up == "island2" and s[1] != "myCaptured")
33+
or (up == "island3" and s[2] != "myCaptured")
34+
):
35+
s = up[-1] + str(x) + "," + str(y - 1)
36+
pirate.setTeamSignal(s)
37+
38+
if (
39+
(down == "island1" and s[0] != "myCaptured")
40+
or (down == "island2" and s[1] != "myCaptured")
41+
or (down == "island3" and s[2] != "myCaptured")
42+
):
43+
s = down[-1] + str(x) + "," + str(y + 1)
44+
pirate.setTeamSignal(s)
45+
46+
if (
47+
(left == "island1" and s[0] != "myCaptured")
48+
or (left == "island2" and s[1] != "myCaptured")
49+
or (left == "island3" and s[2] != "myCaptured")
50+
):
51+
s = left[-1] + str(x - 1) + "," + str(y)
52+
pirate.setTeamSignal(s)
53+
54+
if (
55+
(right == "island1" and s[0] != "myCaptured")
56+
or (right == "island2" and s[1] != "myCaptured")
57+
or (right == "island3" and s[2] != "myCaptured")
58+
):
59+
s = right[-1] + str(x + 1) + "," + str(y)
60+
pirate.setTeamSignal(s)
61+
62+
63+
if pirate.getTeamSignal() != "":
64+
s = pirate.getTeamSignal()
65+
l = s.split(",")
66+
x = int(l[0][1:])
67+
y = int(l[1])
68+
69+
return moveTo(x, y, pirate)
70+
71+
else:
72+
return random.randint(1, 4)
73+
74+
75+
def ActTeam(team):
76+
l = team.trackPlayers()
77+
s = team.getTeamSignal()
78+
79+
team.buildWalls(1)
80+
team.buildWalls(2)
81+
team.buildWalls(3)
82+
83+
if s:
84+
island_no = int(s[0])
85+
signal = l[island_no - 1]
86+
if signal == "myCaptured":
87+
team.setTeamSignal("")

sample_scripts/sample2.py

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import random
2+
import math
3+
4+
name = "sample2"
5+
6+
def moveTo(x, y, Pirate):
7+
position = Pirate.getPosition()
8+
if position[0] == x and position[1] == y:
9+
return 0
10+
if position[0] == x:
11+
return (position[1] < y) * 2 + 1
12+
if position[1] == y:
13+
return (position[0] > x) * 2 + 2
14+
if random.randint(1, 2) == 1:
15+
return (position[0] > x) * 2 + 2
16+
else:
17+
return (position[1] < y) * 2 + 1
18+
19+
20+
def moveAway(x, y, Pirate):
21+
position = Pirate.getPosition()
22+
if position[0] == x and position[1] == y:
23+
return random.randint(1, 4)
24+
if random.randint(1, 2) == 1:
25+
return (position[0] < x) * 2 + 2
26+
else:
27+
return (position[1] > y) * 2 + 1
28+
29+
def circleAround(x, y, radius, Pirate, initial="abc", clockwise=True):
30+
position = Pirate.getPosition()
31+
rx = position[0]
32+
ry = position[1]
33+
pos = [[x + i, y + radius] for i in range(-1 * radius, radius + 1)]
34+
pos.extend([[x + radius, y + i] for i in range(radius - 1, -1 * radius - 1, -1)])
35+
pos.extend([[x + i, y - radius] for i in range(radius - 1, -1 * radius - 1, -1)])
36+
pos.extend([[x - radius, y + i] for i in range(-1 * radius + 1, radius)])
37+
if [rx, ry] not in pos:
38+
if initial != "abc":
39+
return moveTo(initial[0], initial[1], Pirate)
40+
if rx in [x + i for i in range(-1 * radius, radius + 1)] and ry in [
41+
y + i for i in range(-1 * radius, radius + 1)
42+
]:
43+
return moveAway(x, y, Pirate)
44+
else:
45+
return moveTo(x, y, Pirate)
46+
else:
47+
index = pos.index([rx, ry])
48+
return moveTo(
49+
pos[(index + (clockwise * 2) - 1) % len(pos)][0],
50+
pos[(index + (clockwise * 2) - 1) % len(pos)][1],
51+
Pirate,
52+
)
53+
54+
def radius(pirate, x, y, x1, y1, r):
55+
pos = []
56+
for i in range(x1 - r, x1 + r + 1):
57+
for j in range(y1 - r, y1 + r + 1):
58+
pos.append((i, j))
59+
t = 0
60+
if (x, y) in pos:
61+
62+
circleAround(x1, y1, r, pirate)
63+
else:
64+
return moveAway(x1, y1, pirate)
65+
66+
67+
def ActPirate(pirate):
68+
up = pirate.investigate_up()
69+
down = pirate.investigate_down()
70+
left = pirate.investigate_left()
71+
right = pirate.investigate_right()
72+
x, y = pirate.getPosition()
73+
s = pirate.trackPlayers()
74+
tmp1 = ""
75+
tmp2 = ""
76+
tmp3 = ""
77+
tmp4 = ""
78+
if (
79+
(up == "island1" and s[0] != "myCaptured")
80+
or (up == "island2" and s[1] != "myCaptured")
81+
or (up == "island3" and s[2] != "myCaptured")
82+
):
83+
s = up[-1] + str(x) + "," + str(y - 1)
84+
tmp1 = up[-1] + str(x - 2) + "," + str(y - 1)
85+
tmp2 = up[-1] + str(x + 2) + "," + str(y - 1)
86+
tmp3 = up[-1] + str(x) + "," + str(y - 3)
87+
tmp4 = up[-1] + str(x) + "," + str(y + 1)
88+
89+
pirate.setTeamSignal(s)
90+
91+
if (
92+
(down == "island1" and s[0] != "myCaptured")
93+
or (down == "island2" and s[1] != "myCaptured")
94+
or (down == "island3" and s[2] != "myCaptured")
95+
):
96+
s = down[-1] + str(x) + "," + str(y + 1)
97+
tmp1 = up[-1] + str(x - 2) + "," + str(y + 1)
98+
tmp2 = up[-1] + str(x + 2) + "," + str(y + 1)
99+
tmp3 = up[-1] + str(x) + "," + str(y - 1)
100+
tmp4 = up[-1] + str(x) + "," + str(y + 3)
101+
pirate.setTeamSignal(s)
102+
103+
if (
104+
(left == "island1" and s[0] != "myCaptured")
105+
or (left == "island2" and s[1] != "myCaptured")
106+
or (left == "island3" and s[2] != "myCaptured")
107+
):
108+
s = left[-1] + str(x - 1) + "," + str(y)
109+
tmp1 = up[-1] + str(x - 3) + "," + str(y - 1)
110+
tmp2 = up[-1] + str(x + 1) + "," + str(y - 1)
111+
tmp3 = up[-1] + str(x - 1) + "," + str(y - 3)
112+
tmp4 = up[-1] + str(x - 1) + "," + str(y + 1)
113+
pirate.setTeamSignal(s)
114+
115+
if (
116+
(right == "island1" and s[0] != "myCaptured")
117+
or (right == "island2" and s[1] != "myCaptured")
118+
or (right == "island3" and s[2] != "myCaptured")
119+
):
120+
s = right[-1] + str(x + 1) + "," + str(y)
121+
tmp1 = up[-1] + str(x - 1) + "," + str(y - 1)
122+
tmp2 = up[-1] + str(x + 3) + "," + str(y - 1)
123+
tmp3 = up[-1] + str(x + 1) + "," + str(y - 3)
124+
tmp4 = up[-1] + str(x + 1) + "," + str(y + 1)
125+
pirate.setTeamSignal(s)
126+
127+
if tmp1 != "":
128+
pirate.setSignal(tmp1)
129+
ln = 1
130+
elif tmp2 != "":
131+
pirate.setSignal(tmp2)
132+
rn = 1
133+
elif tmp3 != "":
134+
pirate.setSignal(tmp3)
135+
un = 1
136+
elif tmp4 != "":
137+
pirate.setSignal(tmp4)
138+
dn = 1
139+
140+
if pirate.getSignal() != "":
141+
s2 = pirate.getSignal()
142+
l2 = s2.split(",")
143+
x2 = int(l2[0][1:])
144+
y2 = int(l2[1])
145+
position = pirate.getPosition()
146+
if position[0] == x2 and position[1] == y2:
147+
return 0
148+
return moveTo(x2, y2, pirate)
149+
150+
else:
151+
return random.randint(1, 4)
152+
153+
154+
def ActTeam(team):
155+
pass

0 commit comments

Comments
 (0)