Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion create_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def controlled_int_input(prompt, maximum, minimum=0):
for idx in range(game_engine.MOVE_COUNT):
MOVES.append(controlled_int_input('Move #{}: '.format(idx + 1),
game_engine.ALL_MOVES_COUNT, 1) - 1)
BANNED = controlled_int_input('Ban move: ', game_engine.ALL_MOVES_COUNT, 1)
REPLACEMENT = controlled_int_input('Replacement move: ', game_engine.ALL_MOVES_COUNT, 1)
print('Items:')
print(' 0) Nothing (no more items)')
for idx, item in enumerate(game_engine.ITEMS):
Expand All @@ -103,6 +105,8 @@ def controlled_int_input(prompt, maximum, minimum=0):
CSW.stats['Special'] = SPECIAL
CSW.stats['Moves'] = MOVES
CSW.stats['Items'] = ITEMS
CSW.stats['Banned'] = BANNED
CSW.stats['Replacement'] = REPLACEMENT
if game_engine.verify(CSW, CREDITS, STAT_POINTS):
break
print('Invalid strategy settings!')
Expand All @@ -113,7 +117,9 @@ def controlled_int_input(prompt, maximum, minimum=0):
'Defense': CSW.stats['Defense'],
'Special': CSW.stats['Special'],
'Moves': CSW.stats['Moves'],
'Items': CSW.stats['Items']}
'Items': CSW.stats['Items'],
'Banned': CSW.stats['Banned'],
'Replacement': CSW.stats['Replacement']}
with open('{}.py'.format(CONTESTANT_NAME.lower()), 'w') as f:
f.write(STUB_TEXT.format(CSWEEKMON_NAME, STATS_DICT))
f.close()
12 changes: 9 additions & 3 deletions game_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def verify(csweekmon, max_cost=MAX_COST, stat_points=STAT_POINTS):
and len(items) <= MAX_ITEMS
and all([i in range(ALL_ITEMS_COUNT) for i in items])
and sum([item_cost[i] for i in items]) <= max_cost
and effects == [])
and effects == []
and csweekmon.stats['Banned'] not in csweekmon.stats['Moves']
and csweekmon.stats['Banned'] != csweekmon.stats['Replacement'])


def write_stats(turn_number, agent_fst, agent_snd):
Expand Down Expand Up @@ -141,6 +143,10 @@ def run_battle(agent_fst, agent_snd):
Printer.print_ui(' {} is walking...'.format(agent_fst.name))
Printer.delay_ui(1)
Printer.print_ui(' ...a wild {} appears!'.format(agent_snd.name))
agent_fst.stats['Moves'] = [x if x != agent_snd.stats['Banned'] \
else agent_fst.stats['Replacement'] for x in agent_fst.stats['Moves']]
agent_snd.stats['Moves'] = [x if x != agent_fst.stats['Banned'] \
else agent_snd.stats['Replacement'] for x in agent_snd.stats['Moves']]
turn_number = 0
max_turns = 50
current_player = 2
Expand Down Expand Up @@ -186,7 +192,7 @@ def run_battle(agent_fst, agent_snd):
Printer.delay_ui(1)
if agent_cur.stats['PP'] < move.PP_COST:
Printer.print_ui(' But {} does not have enough PP!'.format(agent_cur.name))
elif 'Disabled' in agent_cur.stats['Effects'] and move.CAN_DISABLE:
elif 'Disable' in agent_cur.stats['Effects'] and move.CAN_DISABLE:
Printer.print_ui(' But {} is Disabled!'.format(agent_cur.name))
else:
agent_cur.stats['PP'] -= move.PP_COST
Expand Down Expand Up @@ -228,4 +234,4 @@ def run_battle(agent_fst, agent_snd):
current_player = 0
Printer.print_ui('============================================================')
# Printer.print_ui()
return current_player, turn_number
return current_player
4 changes: 2 additions & 2 deletions moves/blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from utils import Printer

NAME = 'Blast'
PP_COST = 11
SUCCESS_RATE = 70
PP_COST = 8
SUCCESS_RATE = 80
CRIT_RATE = 15
CAN_DISABLE = True

Expand Down
2 changes: 1 addition & 1 deletion moves/blaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

NAME = 'Blaze'
PP_COST = 14
SUCCESS_RATE = 60
SUCCESS_RATE = 80
CRIT_RATE = 15
CAN_DISABLE = True

Expand Down
3 changes: 1 addition & 2 deletions moves/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
NAME = 'Counter'
PP_COST = 5
SUCCESS_RATE = 90
CRIT_RATE = 30
CRIT_RATE = 20
CAN_DISABLE = False

def perform(user, other):
Expand All @@ -29,7 +29,6 @@ def perform(user, other):
Printer.print_ui(' It deals {} point of damage.'.format(damage))
else:
Printer.print_ui(' It deals {} points of damage.'.format(damage))
user.stats['Recent damage'] = damage
other.stats['Recent damage'] = damage
other.stats['HP'] -= damage
else:
Expand Down
2 changes: 1 addition & 1 deletion moves/glare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

NAME = 'Glare'
PP_COST = 4
SUCCESS_RATE = 85
SUCCESS_RATE = 75
CRIT_RATE = 10
CAN_DISABLE = True

Expand Down
4 changes: 2 additions & 2 deletions moves/harden.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from utils import Printer

NAME = 'Harden'
PP_COST = 4
PP_COST = 5
CAN_DISABLE = True

def perform(user, _):
"""Perform Harden."""
increase = random.randint(2, 3 + int(0.1 * user.stats['Special'] * user.stats['Defense']))
user.stats['Defense'] += increase
user.stats['Base Defense'] += increase
Printer.print_ui(' {} increases its Defense by {}.'.format(user.name, increase))
4 changes: 2 additions & 2 deletions moves/mimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def perform(user, other):
"""Perform Mimic."""
move = other.stats['Previous move']
if move is not None:
print_ui(' {} mimics {} using {}.'.format(user.name, other.name, move.NAME))
delay_ui(1)
Printer.print_ui(' {} mimics {} using {}.'.format(user.name, other.name, move.NAME))
Printer.delay_ui(1)
user.stats['Previous move'] = move
move.perform(user, other)
else:
Expand Down
33 changes: 8 additions & 25 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Entry point for the game."""

import argparse
import sys
import math

import game_engine
import strategies
Expand All @@ -12,10 +10,7 @@
STRATEGIES = [
strategies.SimpleStrategy,
strategies.TankStrategy,
strategies.GlassCannonStrategy,
strategies.HeavyHitStrategy,
strategies.RandomStrategy,
strategies.HugePowerStrategy,
strategies.GlassCannonStrategy
]

NSTRATEGIES = len(STRATEGIES)
Expand All @@ -24,14 +19,6 @@
DRAW = dict()
LOSS = dict()

def round2_scoring(k):
if k <= 10:
return 3.0
elif k <= 40:
return 3 - 0.1 * math.floor((k - 10) / 2)
else:
return 1.4

def main():
"""Run tournament."""
# Validate strategies and make sure they have unique names
Expand Down Expand Up @@ -64,24 +51,20 @@ def main():
if SCORES[csw1.name] == -1 or SCORES[csw2.name] == -1:
print(' Battle skipped, at least one competitor was DQ!')
continue
outcome, num_turns = game_engine.run_battle(csw1, csw2)
if outcome == 1 or outcome == 2:
points = round2_scoring(num_turns)

#print('THIS BATTLE HAS FINISHED IN {} TURNS'.format(num_turns), file = sys.stderr)
outcome = game_engine.run_battle(csw1, csw2)
if outcome == 1:
SCORES[csw1.name] += points
SCORES[csw1.name] += 3
WINS[csw1.name] += 1
LOSS[csw2.name] += 1
print(' Winner: {}, and he got {} points for the victory!'.format(csw1.name, points))
print(' Winner: {}'.format(csw1.name))
elif outcome == 2:
SCORES[csw2.name] += points
SCORES[csw2.name] += 3
WINS[csw2.name] += 1
LOSS[csw1.name] += 1
print(' Winner: {}, and he got {} points for the victory!'.format(csw2.name, points))
print(' Winner: {}'.format(csw2.name))
else:
SCORES[csw1.name] += 1.0
SCORES[csw2.name] += 1.0
SCORES[csw1.name] += 1
SCORES[csw2.name] += 1
DRAW[csw1.name] += 1
DRAW[csw2.name] += 1
print(' It\'s a draw!')
Expand Down
Loading