Skip to content

Commit

Permalink
model new version
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidrezaKmK committed Feb 3, 2020
1 parent adfa9ea commit 6bccd32
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
16 changes: 7 additions & 9 deletions AI.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from random import Random


class AI:

def pick(self, world):
self.r = Random()
print("pick")
world.choose_deck([1, 2, 3, 4])
print(world.put_unit(type_id=1, path=world.map.paths[self.r.randint(1, 4)]))
if len(world.player.units) > 0:
print(world.player.units[0].cell)
print(world.get_player_by_id(world.get_my_id()))
print(world.get_player_by_id(world.get_friend_id()))
for p in world.map.paths:
print(p)
print("------------")

print(world.get_path_to_friend(world.get_my_id()))

def turn(self, world):
print("turn")
if len(world.player.units) > 0:
print(world.player.units[0].cell)
84 changes: 51 additions & 33 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


class Map:
def __init__(self, row_num, column_num, paths, kings, cells):
def __init__(self, row_num, column_num, paths, units, kings, cells):
self.row_num = row_num
self.column_num = column_num
self.paths = paths
self.units = []
self.units = units
self.kings = kings
self.cells = cells

Expand All @@ -29,23 +29,25 @@ def add_unit_in_cell(self, row, column, unit):


class Player:
def __init__(self, player_id, king):
def __init__(self, player_id, deck, hand, ap, king, paths_from_player, path_to_friend,
units, cast_area_spell, cast_unit_spell, duplicate_units, hasted_units, played_units,
died_units, range_upgraded_unit = None, damage_upgraded_unit = None):
self.player_id = player_id
self.deck = deck
self.hand = hand
self.ap = ap
self.king = king
self.deck = None
self.hand = []
self.ap = 0
self.paths_from_player = []
self.path_to_friend = []
self.cast_area_spell = []
self.cast_unit_spell = []
self.duplicate_units = []
self.hasted_units = []
self.units = [] # alive units
self.played_units = [] # units that played last turn
self.died_units = []
self.range_upgraded_unit = None # unit that last turn the player upgraded range of it
self.damage_upgraded_unit = None # unit that last turn the player upgraded damage of it
self.paths_from_player = paths_from_player
self.path_to_friend = path_to_friend
self.units = units # alive units
self.cast_area_spell = cast_area_spell
self.cast_unit_spell = cast_unit_spell
self.duplicate_units = duplicate_units
self.hasted_units = hasted_units
self.played_units = played_units # units that played last turn
self.died_units = died_units # units that died last turn
self.range_upgraded_unit = range_upgraded_unit # unit that last turn the player upgraded range of it
self.damage_upgraded_unit = damage_upgraded_unit # unit that last turn the player upgraded damage of it

def is_alive(self):
return self.king.is_alive
Expand All @@ -60,25 +62,25 @@ def __str__(self):


class Unit:
def __init__(self, unit_id, base_unit, cell, path, hp, is_hasted, damage_level,
range_level, range, attack, target, target_cell):
self.unit_id = unit_id
def __init__(self, base_unit, cell, unit_id, hp, path, target, target_cell,
target_if_king, player_id, damage_level, range_level, range,
attack, is_duplicate, is_hasted, affected_spells):
self.base_unit = base_unit
self.cell = cell
self.unit_id = unit_id
self.hp = hp
self.path = path
self.target = target
self.target_cell = target_cell
self.cast_spells_on_unit = []
self.target_if_king = None
self.player_id = 0
self.target_if_king = target_if_king
self.player_id = player_id
self.damage_level = damage_level
self.range_level = range_level
self.range = range
self.attack = attack
self.is_duplicate = False
self.is_duplicate = is_duplicate
self.is_hasted = is_hasted
self.affected_spells = []
self.hp = hp
self.affected_spells = affected_spells


class SpellTarget(Enum):
Expand Down Expand Up @@ -116,6 +118,22 @@ def get_value(string):
return None


class UnitTarget(Enum):
GROUND = 1
AIR = 2
BOTH = 3

@staticmethod
def get_value(string):
if string == "GROUND":
return UnitTarget.GROUND
if string == "AIR":
return UnitTarget.AIR
if string == "BOTH":
return SpellType.BOTH
return None


class Spell:
def __init__(self, type, type_id, duration, priority, target):
self.type = SpellType.get_value(type)
Expand Down Expand Up @@ -172,28 +190,28 @@ def __init__(self):


class BaseUnit:
def __init__(self, type_id, max_hp, base_attack, base_range, target_type, is_flying, is_multiple):
def __init__(self, type_id, max_hp, base_attack, base_range, target_type, is_flying, is_multiple, ap):
self.type_id = type_id
self.max_hp = max_hp
self.ap = 0
self.attack = 0
self.base_attack = base_attack
self.base_range = base_range
self.target_type = target_type
self.is_flying = is_flying
self.is_multiple = is_multiple
self.target_type = target_type
self.ap = ap


class King:
def __init__(self, player_id, target, target_cell, center=None, hp=0, attack=0, range=0, is_alive=True):
def __init__(self, center, hp, attack, range, is_alive, player_id,
target, target_cell):
self.center = center
self.hp = hp
self.attack = attack
self.range = range
self.target = target
self.target_cell = target_cell
self.is_alive = is_alive
self.player_id = player_id
self.target = target
self.target_cell = target_cell


class Message:
Expand Down
2 changes: 1 addition & 1 deletion world.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _base_unit_init(self, msg):
self.base_units = [BaseUnit(type_id=b_unit["typeId"], max_hp=b_unit["maxHP"],
base_attack=b_unit["baseAttack"],
base_range=b_unit["baseRange"],
target_type=b_unit["target_type"],
target_type=b_unit["targetType"],
is_flying=b_unit["isFlying"],
is_multiple=b_unit["isMultiple"])
for b_unit in msg]
Expand Down

0 comments on commit 6bccd32

Please sign in to comment.