Skip to content

Commit

Permalink
add type checks! important to avoid battlecode/battlehack20#121
Browse files Browse the repository at this point in the history
  • Loading branch information
arvid220u committed Aug 20, 2021
1 parent 6adfad0 commit 4fc4062
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions engine/examplefuncsplayer/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import random

from malthusia.stubs import *

Expand All @@ -10,6 +9,7 @@ def dlog(str):
if DEBUG > 0:
log(str)

i = 0

def check_space_wrapper(r, c, board_size):
# check space, except doesn't hit you with game errors
Expand Down Expand Up @@ -66,9 +66,10 @@ def turn():
index = board_size - 1

for _ in range(board_size):
i = random.randint(0, board_size - 1)
global i
if not check_space(index, i):
spawn(index, i)
i += 1
dlog('Spawned unit at: (' + str(index) + ', ' + str(i) + ')')
break

Expand Down
3 changes: 3 additions & 0 deletions engine/malthusia/engine/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def spawn(self, robot, row, col):
Only the HQ can spawn units, and it can only spawn one unit per turn.
:loc should be given as a tuple (row, col), the space to spawn on
"""
if type(row) != type(1) or type(col) != type(1) or type(robot) != type(Robot(0,0,0,0)):
raise RobotError("types are incorrect")

if robot.has_moved:
raise RobotError('you have already spawned a unit this turn')

Expand Down

0 comments on commit 4fc4062

Please sign in to comment.