Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
Inital bots
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwasns99 committed Jan 14, 2019
1 parent 3cc821f commit eaafd5f
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 1 deletion.
60 changes: 60 additions & 0 deletions JS/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {BCAbstractRobot, SPECS} from 'battlecode';

var built = false;
var step = -1;

class MyRobot extends BCAbstractRobot {
turn() {
step++;

if (this.me.unit === SPECS.CRUSADER) {
this.log("START TURN " + step)
this.log("Crusader health: " + this.me.health)

var visible = this.getVisibleRobots()

// this sucks I'm sorry...
var self = this // 'this' fails to properly identify MyRobot when used inside of anonymous function below :(

// get attackable robots
var attackable = visible.filter(function(r){
if (! self.isVisible(r)){
return false
}
var dist = (r.x-self.me.x)**2 + (r.y-self.me.y)**2
if (r.team !== self.me.team
&& SPECS.UNITS[SPECS.CRUSADER].ATTACK_RADIUS[0] <= dist
&& dist <= SPECS.UNITS[SPECS.CRUSADER].ATTACK_RADIUS[1] ){
return true
}
return false
})
this.log(attackable)

if (attackable.length>0){
// attack first robot
var r = attackable[0]
this.log(""+r)
this.log('attacking! ' + r + ' at loc ' + (r.x - this.me.x, r.y - this.me.y))
return this.attack(r.x - this.me.x, r.y - this.me.y)
}

// this.log("Crusader health: " + this.me.health);
const choices = [[0,-1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]];
const choice = choices[Math.floor(Math.random()*choices.length)]
return this.move(...choice);
}

else if (this.me.unit === SPECS.CASTLE) {
if (step % 10 === 0) {
this.log("Building a crusader at " + (this.me.x+1) + ", " + (this.me.y+1));
return this.buildUnit(SPECS.CRUSADER, 1, 1);
} else {
return // this.log("Castle health: " + this.me.health);
}
}

}
}

var robot = new MyRobot();
68 changes: 68 additions & 0 deletions Python/robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from battlecode import BCAbstractRobot, SPECS
import battlecode as bc
import random

__pragma__('iconv')
__pragma__('tconv')
__pragma__('opov')

# don't try to use global variables!!
class MyRobot(BCAbstractRobot):
step = -1

def turn(self):

if self.step == 0:
self.log(SPECS)
self.step += 1
self.log("START TURN " + self.step)

if self.me['unit'] == SPECS['CASTLE']:
if self.step < 10:
self.log("Building a crusader at " + str(self.me['x']+1) + ", " + str(self.me['y']+1))
return self.build_unit(SPECS['CRUSADER'], 1, 1)
else:
self.log("Castle health: " + self.me['health'])

elif self.me['unit'] == SPECS['CHURCH']:
pass #TODO

elif self.me['unit'] == SPECS['PILGRIM']:
pass #TODO

elif self.me['unit'] == SPECS['CRUSADER']:
self.log("Crusader health: " + str(self.me['health']))

visible = self.get_visible_robots()

# get attackable robots
attackable = []
for r in visible:
# x = 5
# if not self.is_visible(r):
if 'x' not in r: #not visible. hacky. do not use at home
continue
# now all in vision range, can see x, y etc
dist = (r['x'] - self.me['x'])**2 + (r['y'] - self.me['y'])**2
if r['team'] != self.me['team'] and SPECS['UNITS'][SPECS["CRUSADER"]]['ATTACK_RADIUS'][0] <= dist <= SPECS['UNITS'][SPECS["CRUSADER"]]['ATTACK_RADIUS'][1]:
attackable.append(r)

if attackable:
# attack first robot
r = attackable[0]
self.log('attacking! ' + str(r) + ' at loc ' + (r['x'] - self.me['x'], r['y'] - self.me['y']))
return self.attack(r['x'] - self.me['x'], r['y'] - self.me['y'])

# The directions: North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest
choices = [(0,-1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1)]
choice = random.choice(choices)
self.log('TRYING TO MOVE IN DIRECTION ' + str(choice))
return self.move(*choice)

elif self.me['unit'] == SPECS['PROPHET']:
pass #TODO

elif self.me['unit'] == SPECS['PREACHER']:
pass #TODO

robot = MyRobot()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# BC_2019
Battlecode 2019

To run, use `bc19run -b JS -r Python`
106 changes: 106 additions & 0 deletions specs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
'COMMUNICATION_BITS': 16,
'CASTLE_TALK_BITS': 8,
'MAX_ROUNDS': 1000,
'TRICKLE_FUEL': 25,
'INITIAL_KARBONITE': 100,
'INITIAL_FUEL': 500,
'MINE_FUEL_COST': 1,
'KARBONITE_YIELD': 2,
'FUEL_YIELD': 10,
'MAX_TRADE': 1024,
'MAX_BOARD_SIZE': 64,
'MAX_ID': 4096,
'CASTLE': 0,
'CHURCH': 1,
'PILGRIM': 2,
'CRUSADER': 3,
'PROPHET': 4,
'PREACHER': 5,
'RED':0,
'BLUE': 1,
'CHESS_INITIAL': 100,
'CHESS_EXTRA': 20,
'TURN_MAX_TIME': 200,
'MAX_MEMORY': 50000000,
'UNITS': [
{
'CONSTRUCTION_KARBONITE': None,
'CONSTRUCTION_FUEL': None,
'KARBONITE_CAPACITY': None,
'FUEL_CAPACITY': None,
'SPEED': 0,
'FUEL_PER_MOVE': None,
'STARTING_HP': 100,
'VISION_RADIUS': 100,
'ATTACK_DAMAGE': None,
'ATTACK_RADIUS': None,
'ATTACK_FUEL_COST': None,
'DAMAGE_SPREAD': None},
{
'CONSTRUCTION_KARBONITE': 50,
'CONSTRUCTION_FUEL': 200,
'KARBONITE_CAPACITY': None,
'FUEL_CAPACITY': None,
'SPEED': 0,
'FUEL_PER_MOVE': None,
'STARTING_HP': 50,
'VISION_RADIUS': 100,
'ATTACK_DAMAGE': None,
'ATTACK_RADIUS': None,
'ATTACK_FUEL_COST': None,
'DAMAGE_SPREAD': None},
{
'CONSTRUCTION_KARBONITE': 10,
'CONSTRUCTION_FUEL': 50,
'KARBONITE_CAPACITY': 20,
'FUEL_CAPACITY': 100,
'SPEED': 4,
'FUEL_PER_MOVE': 1,
'STARTING_HP': 10,
'VISION_RADIUS':100,
'ATTACK_DAMAGE': None,
'ATTACK_RADIUS': None,
'ATTACK_FUEL_COST': None,
'DAMAGE_SPREAD': None},
{
'CONSTRUCTION_KARBONITE': 20,
'CONSTRUCTION_FUEL': 50,
'KARBONITE_CAPACITY': 20,
'FUEL_CAPACITY': 100,
'SPEED': 9,
'FUEL_PER_MOVE': 1,
'STARTING_HP': 40,
'VISION_RADIUS': 36,
'ATTACK_DAMAGE': 10,
'ATTACK_RADIUS': [1, 16],
'ATTACK_FUEL_COST': 10,
'DAMAGE_SPREAD': 0},
{
'CONSTRUCTION_KARBONITE': 25,
'CONSTRUCTION_FUEL': 50,
'KARBONITE_CAPACITY': 20,
'FUEL_CAPACITY': 100,
'SPEED': 4,
'FUEL_PER_MOVE': 2,
'STARTING_HP': 20,
'VISION_RADIUS': 64,
'ATTACK_DAMAGE': 10,
'ATTACK_RADIUS': [16, 64],
'ATTACK_FUEL_COST': 25,
'DAMAGE_SPREAD': 0},
{
'CONSTRUCTION_KARBONITE': 30,
'CONSTRUCTION_FUEL': 50,
'KARBONITE_CAPACITY': 20,
'FUEL_CAPACITY': 100,
'SPEED': 4,
'FUEL_PER_MOVE': 3,
'STARTING_HP': 60,
'VISION_RADIUS': 16,
'ATTACK_DAMAGE': 20,
'ATTACK_RADIUS': [1, 16],
'ATTACK_FUEL_COST': 15,
'DAMAGE_SPREAD': 3
}]
}

0 comments on commit eaafd5f

Please sign in to comment.