def test_basic_add_attack_dice_three(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Blank] ***") parser.add_line("* *** sozin added a Crit ***") parser.add_line("* *** sozin added a Hit ***") parser.add_line("* *** sozin added a Hit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] self.assertEqual("sozin", throw.player.name) self.assertEqual(1, throw.attack_set_num) self.assertEqual(throw.throw_type, DiceThrowType.ATTACK) results = throw.results self.assertEqual(4, len(results)) d1 = results[0] self.assertEqual(DiceFace.BLANK, d1.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual(DiceFace.CRIT, d2.final_dice.dice_face) self.assertEqual(Dice.ADDED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual(DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual(Dice.ADDED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual(DiceFace.HIT, d4.final_dice.dice_face) self.assertEqual(Dice.ADDED, d4.final_dice.dice_origination)
def main(): args = init_args() lfp = LogFileParser(args.log_file) lfp.parse_log() lfp.total_time_period() lfp.total_times_for_pids() lfp.filter_only_viewable() pps = PrintableProcesses() pps.scale_bars(lfp) print_bars(pps, args.output_path)
def test_basic_add_attack_dice_three(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Blank] ***") parser.add_line("* *** sozin added a Crit ***") parser.add_line("* *** sozin added a Hit ***") parser.add_line("* *** sozin added a Hit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] self.assertEqual( "sozin", throw.player.name) self.assertEqual( 1, throw.attack_set_num) self.assertEqual( throw.throw_type, DiceThrowType.ATTACK) results = throw.results self.assertEqual( 4, len(results)) d1 = results[0] self.assertEqual( DiceFace.BLANK, d1.final_dice.dice_face ) self.assertEqual( Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual( DiceFace.CRIT, d2.final_dice.dice_face) self.assertEqual( Dice.ADDED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual( DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual( Dice.ADDED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual( DiceFace.HIT, d4.final_dice.dice_face) self.assertEqual( Dice.ADDED, d4.final_dice.dice_origination)
def setUp(self): self.parser = LogFileParser(None) self.parser.read_input_from_file("../logfiles/fsm_test_input.txt") self.parser.run_finite_state_machine() self.game_tape = self.parser.game_tape self.g = Game(None, self.parser.get_players()) for throw_result in self.game_tape: self.g.game_throws.append(throw_result) self.tape = GameTape(self.g) self.tape.score()
def test_cancel(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line( "* *** sozin Rolls to Attack: [Crit], [Hit], [Hit], [], [], [] ***" ) parser.add_line("* *** tal cancels Hit ***") parser.add_line("* *** tal cancels Hit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] results = throw.results self.assertEqual(3, len(results)) d1 = results[0] self.assertEqual(DiceFace.CRIT, d1.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual(DiceFace.HIT, d2.final_dice.dice_face) self.assertEqual(1, len(d2.adjustments)) adj = d2.adjustments[0] self.assertEqual(DiceThrowAdjustmentType.CANCELLED, adj.adjustment_type) d3 = results[2] self.assertEqual(DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d3.final_dice.dice_origination) adj = d3.adjustments[0] self.assertEqual(DiceThrowAdjustmentType.CANCELLED, adj.adjustment_type)
def test_cancel(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Crit], [Hit], [Hit], [], [], [] ***") parser.add_line("* *** tal cancels Hit ***") parser.add_line("* *** tal cancels Hit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] results = throw.results self.assertEqual( 3, len(results)) d1 = results[0] self.assertEqual( DiceFace.CRIT, d1.final_dice.dice_face ) self.assertEqual( Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual( DiceFace.HIT, d2.final_dice.dice_face) self.assertEqual( 1, len(d2.adjustments)) adj = d2.adjustments[0] self.assertEqual(DiceThrowAdjustmentType.CANCELLED, adj.adjustment_type) d3 = results[2] self.assertEqual( DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual( Dice.ROLLED, d3.final_dice.dice_origination) adj = d3.adjustments[0] self.assertEqual(DiceThrowAdjustmentType.CANCELLED, adj.adjustment_type)
def add_game(): tape = request.form['chatlog'] winner = request.form['winner'] if len(tape) == 0: return redirect(url_for('new')) try: parser = LogFileParser(session) parser.read_input_from_string(tape) parser.run_finite_state_machine() if len(parser.get_players()) is not 2: #this is not good, probably a result of a bad log file submission return render_template('new_after_error.html', players=", ".join(parser.get_players()), tape=tape, winner=winner) game = Game(session, parser.get_players()) p1 = game.game_players[0] p2 = game.game_players[1] winning_player = None if winner is not None: if winner == p1.name: winning_player = p1 elif winner == p2.name: winning_player = p2 game.game_winner = winning_player for throw_result in parser.game_tape: game.game_throws.append(throw_result) session.add(game) session.commit() save_game_log(tape, is_good=True) return redirect(url_for('game', id=str(game.id))) except Exception as err: save_game_log(tape, is_good=False) return render_template('game_error.html', errortext=str(err))
def setUp(self): self.parser = LogFileParser(None) self.parser.read_input_from_file("../logfiles/fsm_test_input.txt") self.parser.run_finite_state_machine() self.game_tape = self.parser.game_tape self.g = Game(None,self.parser.get_players()) for throw_result in self.game_tape: self.g.game_throws.append(throw_result) self.tape = GameTape( self.g ) self.tape.score()
def main(self, args): self.parser = LogFileParser() for processor in self.processors: processor.begin() if self.options.merge: i = 0 for j in range(len(args)): if args[j] == '/': self.processFiles(args[i:j]) i = j + 1 self.processFiles(args[i:]) else: for fname in args: self.processFiles([fname]) for processor in self.processors: processor.end()
def add_game(): tape = request.form['chatlog'] winner = request.form['winner'] if len(tape) == 0: return redirect(url_for('new')) try: parser = LogFileParser(session) parser.read_input_from_string(tape) parser.run_finite_state_machine() if len(parser.get_players() ) is not 2: #this is not good, probably a result of a bad log file submission return render_template('new_after_error.html', players=", ".join(parser.get_players()), tape=tape, winner=winner) game = Game( session, parser.get_players()) p1 = game.game_players[0] p2 = game.game_players[1] winning_player = None if winner is not None: if winner == p1.name: winning_player = p1 elif winner == p2.name: winning_player = p2 game.game_winner = winning_player for throw_result in parser.game_tape: game.game_throws.append(throw_result) session.add(game) session.commit() save_game_log( tape, is_good=True) return redirect( url_for('game', id=str(game.id) ) ) except Exception as err: save_game_log( tape, is_good=False) return render_template( 'game_error.html', errortext=str(err) )
def testGameWithPlayer(self): parser = LogFileParser(self.session) parser.read_input_from_file("../logfiles/fsm_test_input.txt") parser.run_finite_state_machine() g = Game(self.session, parser.get_players()) p1 = g.game_players[0] p2 = g.game_players[1] g.game_winner = p1 session = self.session session.add(g) session.commit() my_g = self.persistence_manager.get_game(g.id) self.assertTrue( my_g is not None) self.assertEqual( g.game_name, my_g.game_name) self.assertTrue( len(g.game_players) == 2 ) self.assertEqual( g.game_players[0].name , "Ryan") self.assertTrue( g.game_players[1].name == "sozin") self.assertTrue( g.game_winner is not None) self.assertTrue( g.game_winner.name == "Ryan") my_player1 = self.persistence_manager.get_player(p1) self.assertEqual("Ryan", my_player1.name) self.assertTrue( my_player1.id == g.game_players[0].id) my_player2 = self.persistence_manager.get_player(p2) self.assertEqual("sozin", my_player2.name) self.assertTrue( my_player2.id == g.game_players[1].id ) #change the name of something and verify that the id remains the game p1.name = "Darth Vader" session.add(p1) session.commit() vader = self.persistence_manager.get_player(p1) self.assertEqual( my_player1.id, vader.id )
def test_basic_add_attack_dice(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line( "* *** sozin Rolls to Attack: [Hit], [Focus], [Blank], [], [], [], [] ***" ) parser.add_line("* *** sozin added a Crit ***") parser.add_line( "* *** sozin Re-Rolls Attack Die 3 [Blank] and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Attack Dice ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] self.assertEqual("sozin", throw.player.name) self.assertEqual(1, throw.attack_set_num) self.assertEqual(throw.throw_type, DiceThrowType.ATTACK) results = throw.results self.assertEqual(4, len(results)) d1 = results[0] self.assertEqual(DiceFace.HIT, d1.final_dice.dice_face) d2 = results[1] self.assertEqual(DiceFace.HIT, d2.final_dice.dice_face) d3 = results[2] self.assertEqual(DiceFace.HIT, d3.final_dice.dice_face) d4 = results[3] self.assertEqual(DiceFace.CRIT, d4.final_dice.dice_face)
def testTape(self): session = self.session parser = LogFileParser(self.session) parser.read_input_from_file("../logfiles/fsm_test_input.txt") parser.run_finite_state_machine() game_tape = parser.game_tape g = Game(self.session, parser.get_players()) p1 = g.game_players[0] p2 = g.game_players[1] for throw_result in game_tape: g.game_throws.append(throw_result) session.add(g) session.commit() #now get 'em back my_g = self.persistence_manager.get_game(g.id) self.assertTrue( g is not None ) throws = my_g.game_throws self.assertTrue( throws is not None) self.assertEqual( len(throws) , 8 ) #* *** Ryan Rolls to Attack: [Focus], [Blank], [], [], [], [], [] *** #* *** Ryan turns Attack Die 1 (Focus) into a [Hit] *** throw = throws[0] self.assertEqual( g.id, throw.game_id) self.assertEqual( p1.name, throw.player.name) self.assertEqual( DiceThrowType.ATTACK, throw.throw_type ) self.assertEqual( 1, throw.attack_set_num) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.FOCUS, result.dice.dice_face) self.assertEqual( 1, len (result.adjustments)) self.assertEqual( DiceFace.HIT, result.final_dice.dice_face) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.HIT, adjustment.to_dice.dice_face) result = throw.results[1] self.assertEqual( 2, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.BLANK, result.dice.dice_face) self.assertEqual( 0, len (result.adjustments)) self.assertEqual( DiceFace.BLANK, result.final_dice.dice_face) #* *** sozin Rolls to Defend: [Evade], [Blank], [Evade], [], [], [], [] *** throw = throws[1] self.assertEqual( g.id, throw.game_id) self.assertEqual( p2.name, throw.player.name) self.assertEqual( DiceThrowType.DEFEND, throw.throw_type ) self.assertEqual( 1, throw.attack_set_num) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.EVADE, result.dice.dice_face) self.assertEqual( 0, len (result.adjustments)) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) result = throw.results[1] self.assertEqual( 2, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.BLANK, result.dice.dice_face) self.assertEqual( 0, len (result.adjustments)) self.assertEqual( DiceFace.BLANK, result.final_dice.dice_face) result = throw.results[2] self.assertEqual( 3, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.EVADE, result.dice.dice_face) self.assertEqual( 0, len (result.adjustments)) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) #* *** Ryan Rolls to Attack: [Hit], [Crit], [], [], [], [], [] *** throw = throws[2] self.assertEqual( g.id, throw.game_id) self.assertEqual( p1.name, throw.player.name) self.assertEqual( DiceThrowType.ATTACK, throw.throw_type ) self.assertEqual( 2, throw.attack_set_num) self.assertEqual( 2, len( throw.results )) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.HIT, result.dice.dice_face) self.assertEqual( DiceFace.HIT, result.final_dice.dice_face) self.assertEqual( 0, len (result.adjustments)) result = throw.results[1] self.assertEqual( 2, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.CRIT, result.dice.dice_face) self.assertEqual( DiceFace.CRIT, result.final_dice.dice_face) self.assertEqual( 0, len (result.adjustments)) #* *** sozin Rolls to Defend: [Focus], [], [], [], [], [], [] *** #* *** sozin turns Defense Die 1 (Focus) into a [Evade] *** throw = throws[3] self.assertEqual( g.id, throw.game_id) self.assertEqual( p2.name, throw.player.name) self.assertEqual( DiceThrowType.DEFEND, throw.throw_type ) self.assertEqual( 2, throw.attack_set_num) self.assertEqual( 1, len( throw.results)) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.FOCUS, result.dice.dice_face) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) self.assertEqual( 1, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.EVADE, adjustment.to_dice.dice_face) #* *** sozin Rolls to Attack: [Blank], [Blank], [], [], [], [], [] *** #<sozin> - tl #* *** sozin Re-Rolls Attack Die 1 [Blank] and gets a [Focus] *** #* *** sozin Re-Rolls Attack Die 2 [Focus] and gets a [Focus] *** #* *** sozin turns Attack Die 1 (Focus) into a [Hit] *** #* *** sozin turns Attack Die 2 (Focus) into a [Hit] *** throw = throws[4] self.assertEqual( g.id, throw.game_id) self.assertEqual( p2.name, throw.player.name) self.assertEqual( DiceThrowType.ATTACK, throw.throw_type ) self.assertEqual( 3, throw.attack_set_num) self.assertEqual( 2, len( throw.results)) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.BLANK, result.dice.dice_face) self.assertEqual( DiceFace.HIT, result.final_dice.dice_face) self.assertEqual( 1, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.REROLL, adjustment.adjustment_type) self.assertEqual( DiceFace.BLANK, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.HIT, adjustment.to_dice.dice_face) result = throw.results[1] self.assertEqual( 2, result.dice_num) self.assertEqual( DiceType.RED, result.dice.dice_type) self.assertEqual( DiceFace.BLANK, result.dice.dice_face) self.assertEqual( DiceFace.CRIT, result.final_dice.dice_face) self.assertEqual( 2, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.REROLL, adjustment.adjustment_type) self.assertEqual( DiceFace.BLANK, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.FOCUS, adjustment.to_dice.dice_face) adjustment = result.adjustments[1] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.CRIT, adjustment.to_dice.dice_face) #* *** Ryan Rolls to Defend: [Focus], [Blank], [Focus], [], [], [], [] *** #* *** Ryan Re-Rolls Defense Die 2 (Blank) and gets a [Focus] *** #* *** Ryan turns Defense Die 1 (Focus) into a [Evade] *** #* *** Ryan turns Defense Die 2 (Focus) into a [Evade] *** #* *** Ryan turns Defense Die 3 (Focus) into a [Evade] *** throw = throws[5] self.assertEqual( g.id, throw.game_id) self.assertEqual( p1.name, throw.player.name) self.assertEqual( DiceThrowType.DEFEND, throw.throw_type ) self.assertEqual( 3, throw.attack_set_num) self.assertEqual( 3, len( throw.results)) result = throw.results[0] self.assertEqual( 1, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.FOCUS, result.dice.dice_face) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) self.assertEqual( 1, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.EVADE, adjustment.to_dice.dice_face) result = throw.results[1] self.assertEqual( 2, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.BLANK, result.dice.dice_face) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) self.assertEqual( 2, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.REROLL, adjustment.adjustment_type) self.assertEqual( DiceFace.BLANK, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.FOCUS, adjustment.to_dice.dice_face) adjustment = result.adjustments[1] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.EVADE, adjustment.to_dice.dice_face) result = throw.results[2] self.assertEqual( 3, result.dice_num) self.assertEqual( DiceType.GREEN, result.dice.dice_type) self.assertEqual( DiceFace.FOCUS, result.dice.dice_face) self.assertEqual( DiceFace.EVADE, result.final_dice.dice_face) self.assertEqual( 1, len (result.adjustments)) adjustment = result.adjustments[0] self.assertEqual( adjustment.base_result_id, result.id) self.assertEqual( DiceThrowAdjustmentType.CONVERT, adjustment.adjustment_type) self.assertEqual( DiceFace.FOCUS, adjustment.from_dice.dice_face ) self.assertEqual( DiceFace.EVADE, adjustment.to_dice.dice_face)
def test_attack_roll_focus_reroll_turn(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Blank], [Blank], [Blank], [], [], [] ***") parser.add_line("* *** sozin turns Attack Die 1 [Blank] into a [Hit] ***") parser.add_line("* *** sozin turns Attack Die 2 [Blank] into a [Focus] ***") parser.add_line("* *** sozin Re-Rolls Attack Die 3 [Blank] and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Attack Dice ***") parser.add_line("* *** sozin added a Crit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] results = throw.results self.assertEqual( 4, len(results)) d1 = results[0] self.assertEqual( DiceFace.HIT, d1.final_dice.dice_face ) self.assertEqual( Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual( DiceFace.HIT, d2.final_dice.dice_face) self.assertEqual( Dice.ROLLED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual( DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual( Dice.ROLLED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual( DiceFace.CRIT, d4.final_dice.dice_face) self.assertEqual( Dice.ADDED, d4.final_dice.dice_origination)
def testDoubleGameLoadPlayersRemainTheSame(self): parser = LogFileParser(self.session) parser.read_input_from_file("../logfiles/fsm_test_input.txt") parser.run_finite_state_machine() g = Game(self.session, parser.get_players()) p1 = g.game_players[0] p2 = g.game_players[1] g.game_winner = p1 session = self.session session.add(g) session.commit() parser = LogFileParser(self.session) parser.read_input_from_file("../logfiles/fsm_test_input.txt") parser.run_finite_state_machine() g = Game(self.session, parser.get_players()) session.add(g) session.commit() p1a = g.game_players[0] p2a = g.game_players[1] g.game_winner = p1a session = self.session session.add (g) session.commit() self.assertTrue( p1.id == p1a.id) self.assertTrue( p2.id == p2a.id ) session.flush(p1) session.flush(p2)
def test_basic_add_attack_dice(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Hit], [Focus], [Blank], [], [], [], [] ***") parser.add_line("* *** sozin added a Crit ***") parser.add_line("* *** sozin Re-Rolls Attack Die 3 [Blank] and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Attack Dice ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] self.assertEqual( "sozin", throw.player.name) self.assertEqual( 1, throw.attack_set_num) self.assertEqual( throw.throw_type, DiceThrowType.ATTACK) results = throw.results self.assertEqual( 4, len(results)) d1 = results[0] self.assertEqual( DiceFace.HIT, d1.final_dice.dice_face ) d2 = results[1] self.assertEqual( DiceFace.HIT, d2.final_dice.dice_face) d3 = results[2] self.assertEqual( DiceFace.HIT, d3.final_dice.dice_face) d4 = results[3] self.assertEqual( DiceFace.CRIT, d4.final_dice.dice_face)
class GameTapeTester(unittest.TestCase): def setUp(self): self.parser = LogFileParser(None) self.parser.read_input_from_file("../logfiles/fsm_test_input.txt") self.parser.run_finite_state_machine() self.game_tape = self.parser.game_tape self.g = Game(None,self.parser.get_players()) for throw_result in self.game_tape: self.g.game_throws.append(throw_result) self.tape = GameTape( self.g ) self.tape.score() def testDamage(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] p1_damage = self.g.game_tape.damage( p1 ) p2_damage = self.g.game_tape.damage( p2 ) self.assertEqual( 0, p1_damage[0]) self.assertEqual( 0, p1_damage[1]) self.assertEqual( 1, p1_damage[2]) self.assertEqual( 1, p1_damage[3]) self.assertEqual( 1, p1_damage[4]) self.assertEqual( 0, p2_damage[0]) self.assertEqual( 0, p2_damage[1]) self.assertEqual( 0, p2_damage[2]) self.assertEqual( 0, p2_damage[3]) self.assertEqual( 0, p2_damage[4]) def testCumulativeStats(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] self.assertEqual( 4, self.g.total_reds( p1) ) self.assertEqual( 3, self.g.total_reds( p2) ) p1_init_reds = self.g.game_tape.initial_red_scores(p1) self.assertEqual( 5, len(p1_init_reds)) self.assertEqual( 0, p1_init_reds[0]) self.assertEqual( -0.8125, p1_init_reds[1]) self.assertEqual( 0.125, p1_init_reds[2]) self.assertEqual( 0.125, p1_init_reds[3]) self.assertEqual( 0.125, p1_init_reds[4]) p1_reds = self.g.game_tape.final_red_scores( p1 ) self.assertEqual( 5, len(p1_reds)) self.assertEqual( 0, p1_reds[0]) self.assertEqual( -0.3125, p1_reds[1]) self.assertEqual( 0.625, p1_reds[2]) self.assertEqual( 0.625, p1_reds[3]) self.assertEqual( 0.625, p1_reds[4]) p2_reds = self.g.game_tape.final_red_scores( p2 ) self.assertEqual( 5, len(p2_reds)) self.assertEqual( 0, p2_reds[0]) self.assertEqual( 0, p2_reds[1]) self.assertEqual( 0, p2_reds[2]) self.assertEqual( 0.9375, p2_reds[3]) self.assertEqual( 1.53125, p2_reds[4]) p1_greens = self.g.game_tape.final_green_scores( p1 ) self.assertEqual( 5, len(p1_greens)) self.assertEqual(0, p1_greens[0]) self.assertEqual(0, p1_greens[1]) self.assertEqual(0, p1_greens[2]) self.assertEqual(1.3125, p1_greens[3]) self.assertEqual(0.625, p1_greens[4]) p2_greens = self.g.game_tape.final_green_scores( p2 ) print p2_greens self.assertEqual( 5, len(p2_greens)) self.assertEqual( 0, p2_greens[0]) self.assertEqual( 0.3125, p2_greens[1]) self.assertEqual( 0.75, p2_greens[2]) self.assertEqual( 0.75, p2_greens[3]) self.assertEqual( 0.75, p2_greens[4]) def testRawSummaryStats(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] #HITS #totals first self.assertEqual( 4, self.g.total_reds( p1) ) self.assertEqual( 3, self.g.total_reds( p2) ) #p1, initial rolls self.assertEqual( 1, self.g.unmodified_hits( p1 ) ) self.assertEqual( (3.0/8.0) * 4 , self.g.expected_unmodified_hits( p1 ) ) #p2, initial roles self.assertEqual( 0, self.g.unmodified_hits( p2 ) ) self.assertEqual( (3.0/8.0) * 3 , self.g.expected_unmodified_hits( p2 ) ) #p1, after rerolls self.assertEqual( 1, self.g.total_red_hits_after_rerolls( p1 ) ) self.assertEqual( 1.5, self.g.expected_hits_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 1, self.g.total_red_hits_after_rerolls( p2 ) ) self.assertEqual( (3.0/8.0) * 5, self.g.expected_hits_after_rerolls( p2 )) #p1, after converts self.assertEqual( 2, self.g.total_red_hits_after_converts( p1 ) ) self.assertEqual( 1.5, self.g.expected_hits_after_converts ( p1 )) #p2, after converts self.assertEqual( 1, self.g.total_red_hits_after_converts( p2 ) ) self.assertEqual( (3.0/8.0) * 5, self.g.expected_hits_after_converts ( p2 )) #CRITS #p1, initial rolls self.assertEqual( 1, self.g.unmodified_crits( p1 ) ) self.assertEqual( (1.0/8.0) * 4 , self.g.expected_unmodified_crits( p1 ) ) #p2, initial roles self.assertEqual( 1, self.g.unmodified_crits( p2 ) ) self.assertEqual( (1.0/8.0) * 3 , self.g.expected_unmodified_crits( p2 ) ) #p1, after rerolls self.assertEqual( 1, self.g.total_red_crits_after_rerolls( p1 ) ) self.assertEqual( .5, self.g.expected_crits_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 1, self.g.total_red_crits_after_rerolls( p2 ) ) self.assertEqual( (1.0/8.0) * 5, self.g.expected_crits_after_rerolls( p2 )) #p1, after converts self.assertEqual( 1, self.g.total_red_crits_after_converts( p1 ) ) self.assertEqual( .5, self.g.expected_crits_after_converts ( p1 )) #p2, after converts self.assertEqual( 2, self.g.total_red_crits_after_converts( p2 ) ) self.assertEqual( (1.0/8.0) * 5, self.g.expected_crits_after_converts ( p2 )) #RED FOCUS #p1, initial rolls self.assertEqual( 1, self.g.unmodified_focuses( p1 ) ) self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_focuses( p1 ) ) #p2, initial roles self.assertEqual( 0, self.g.unmodified_focuses( p2 ) ) self.assertEqual( (2.0/8.0) * 3 , self.g.expected_unmodified_focuses( p2 ) ) #p1, after rerolls self.assertEqual( 1, self.g.total_red_focuses_after_rerolls( p1 ) ) self.assertEqual( 4 * (2.0/8.0), self.g.expected_focuses_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 1, self.g.total_red_focuses_after_rerolls( p2 ) ) self.assertEqual( (2.0/8.0) * 5, self.g.expected_focuses_after_rerolls( p2 )) #p1, after converts self.assertEqual( 0, self.g.total_red_focuses_after_converts( p1 ) ) self.assertEqual( (2.0/8.0) * 4, self.g.expected_focuses_after_converts ( p1 )) #p2, after converts self.assertEqual( 0, self.g.total_red_focuses_after_converts( p2 ) ) self.assertEqual( (2.0/8.0) * 5, self.g.expected_focuses_after_converts ( p2 )) #RED BLANK #p1, initial blank rolls self.assertEqual( 1, self.g.unmodified_blanks( p1 ) ) self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_blanks( p1 ) ) #p2, initial blank rolls self.assertEqual( 2, self.g.unmodified_blanks( p2 ) ) self.assertEqual( (2.0/8.0) * 3 , self.g.expected_unmodified_focuses( p2 ) ) #p1, blanks after rerolls self.assertEqual( 1, self.g.total_red_blanks_after_rerolls( p1 ) ) self.assertEqual( 4 * (2.0/8.0), self.g.expected_blanks_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 2, self.g.total_red_blanks_after_rerolls( p2 ) ) self.assertEqual( (2.0/8.0) * 5, self.g.expected_blanks_after_rerolls( p2 )) #p1, after converts self.assertEqual( 1, self.g.total_red_blanks_after_converts( p1 ) ) self.assertEqual( (2.0/8.0) * 4, self.g.expected_blanks_after_converts ( p1 )) #p2, after converts self.assertEqual( 2, self.g.total_red_blanks_after_converts( p2 ) ) self.assertEqual( (2.0/8.0) * 5, self.g.expected_blanks_after_converts ( p2 )) #green dice self.assertEqual( 6, self.g.total_greens(p1)) self.assertEqual( 4, self.g.total_greens(p2)) #EVADES self.assertEqual( 0, self.g.unmodified_evades(p1)) self.assertEqual( (3.0/8.0) * 6, self.g.expected_unmodified_evades(p1)) self.assertEqual( 2, self.g.unmodified_evades(p2)) self.assertEqual( (3.0/8.0) * 4, self.g.expected_unmodified_evades(p2)) #p1, after rerolls self.assertEqual( 0, self.g.total_green_evades_after_rerolls( p1 ) ) self.assertEqual( (3.0/8.0) * 7, self.g.expected_green_evades_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 2, self.g.total_green_evades_after_rerolls( p2 ) ) self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_evades_after_rerolls( p2 )) #p1, after converts self.assertEqual( 4, self.g.total_green_evades_after_converts( p1 ) ) self.assertEqual( (3.0/8.0) * 7 , self.g.expected_green_evades_after_converts ( p1 )) #p2, after converts self.assertEqual( 3, self.g.total_green_evades_after_converts( p2 ) ) self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_evades_after_converts ( p2 )) #GREEN FOCUSES self.assertEqual( 3, self.g.unmodified_green_focuses( p1 ) ) self.assertEqual( (2.0/8.0) * 6 , self.g.expected_unmodified_green_focuses( p1 ) ) #p2, initial roles self.assertEqual( 1, self.g.unmodified_green_focuses( p2 ) ) self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_green_focuses( p2 ) ) #p1, after rerolls self.assertEqual( 4, self.g.total_green_focuses_after_rerolls( p1 ) ) self.assertEqual( 7 * (2.0/8.0), self.g.expected_green_focuses_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 1, self.g.total_green_focuses_after_rerolls( p2 ) ) self.assertEqual( (2.0/8.0) * 4, self.g.expected_green_focuses_after_rerolls( p2 )) #p1, after converts self.assertEqual( 0, self.g.total_green_focuses_after_converts( p1 ) ) self.assertEqual( (2.0/8.0) * 7, self.g.expected_green_focuses_after_converts ( p1 )) #p2, after converts self.assertEqual( 0, self.g.total_green_focuses_after_converts( p2 ) ) self.assertEqual( (2.0/8.0) * 4, self.g.expected_green_focuses_after_converts ( p2 )) #GREEN BLANKS self.assertEqual( 3, self.g.unmodified_green_blanks( p1 ) ) self.assertEqual( (3.0/8.0) * 6 , self.g.expected_unmodified_green_blanks( p1 ) ) #p2, initial roles self.assertEqual( 1, self.g.unmodified_green_blanks( p2 ) ) self.assertEqual( (3.0/8.0) * 4 , self.g.expected_unmodified_green_blanks( p2 ) ) #p1, after rerolls self.assertEqual( 3, self.g.total_green_blanks_after_rerolls( p1 ) ) self.assertEqual( 7 * (3.0/8.0), self.g.expected_green_blanks_after_rerolls( p1 )) #p2, after rerolls self.assertEqual( 1, self.g.total_green_blanks_after_rerolls( p2 ) ) self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_blanks_after_rerolls( p2 )) #p1, after converts self.assertEqual( 3, self.g.total_green_blanks_after_converts( p1 ) ) self.assertEqual( (3.0/8.0) * 7, self.g.expected_green_blanks_after_converts ( p1 )) #p2, after converts self.assertEqual( 1, self.g.total_green_blanks_after_converts( p2 ) ) self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_blanks_after_converts ( p2 )) def testAttackSetStats(self): self.assertEqual( 4, len(self.tape.attack_sets) ) aset = self.tape.attack_sets[0] self.assertEqual( -.3125, aset.total_attack_end_luck() ) self.assertEqual( .3125, aset.total_defense_end_luck() ) aset = self.tape.attack_sets[1] self.assertEqual( .9375, aset.total_attack_end_luck() ) self.assertEqual( 0.4375, aset.total_defense_end_luck() ) aset = self.tape.attack_sets[2] self.assertEqual( 0.9375, aset.total_attack_end_luck() ) self.assertEqual( 1.3125, aset.total_defense_end_luck() ) aset = self.tape.attack_sets[3] self.assertEqual( 0.59375, aset.total_attack_end_luck() ) self.assertEqual( -0.6875, aset.total_defense_end_luck() )
def test_add_evade(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Blank] ***") parser.add_line("* *** tal Rolls to Defend: [Blank], [Blank], [Focus], [], [], [], [] ***") parser.add_line("* *** tal Re-Rolls Defense Die 1 (Blank) and gets a [Focus] ***") parser.add_line("* *** tal Re-Rolls Defense Die 2 (Blank) and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Defense Dice ***") parser.add_line("* *** tal added an Evade ***") parser.run_finite_state_machine() gt = parser.game_tape self.assertEqual( 2, len(gt)) attack_throw = gt[0] self.assertEqual( "sozin", attack_throw.player.name) self.assertEqual( 1, attack_throw.attack_set_num) self.assertEqual( attack_throw.throw_type, DiceThrowType.ATTACK) results = attack_throw.results self.assertEqual( 1, len(results)) defense_throw = gt[1] self.assertEqual( "tal", defense_throw.player.name) self.assertEqual( 1, defense_throw.attack_set_num) self.assertEqual( defense_throw.throw_type, DiceThrowType.DEFEND) results = defense_throw.results self.assertEqual( 4, len(results)) d1 = results[0] self.assertEqual( DiceFace.EVADE, d1.final_dice.dice_face ) self.assertEqual( Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual( DiceFace.EVADE, d2.final_dice.dice_face) self.assertEqual( Dice.ROLLED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual( DiceFace.EVADE, d3.final_dice.dice_face) self.assertEqual( Dice.ROLLED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual( DiceFace.EVADE, d4.final_dice.dice_face) self.assertEqual( Dice.ADDED, d4.final_dice.dice_origination)
def test_add_evade(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line("* *** sozin Rolls to Attack: [Blank] ***") parser.add_line( "* *** tal Rolls to Defend: [Blank], [Blank], [Focus], [], [], [], [] ***" ) parser.add_line( "* *** tal Re-Rolls Defense Die 1 (Blank) and gets a [Focus] ***") parser.add_line( "* *** tal Re-Rolls Defense Die 2 (Blank) and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Defense Dice ***") parser.add_line("* *** tal added an Evade ***") parser.run_finite_state_machine() gt = parser.game_tape self.assertEqual(2, len(gt)) attack_throw = gt[0] self.assertEqual("sozin", attack_throw.player.name) self.assertEqual(1, attack_throw.attack_set_num) self.assertEqual(attack_throw.throw_type, DiceThrowType.ATTACK) results = attack_throw.results self.assertEqual(1, len(results)) defense_throw = gt[1] self.assertEqual("tal", defense_throw.player.name) self.assertEqual(1, defense_throw.attack_set_num) self.assertEqual(defense_throw.throw_type, DiceThrowType.DEFEND) results = defense_throw.results self.assertEqual(4, len(results)) d1 = results[0] self.assertEqual(DiceFace.EVADE, d1.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual(DiceFace.EVADE, d2.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual(DiceFace.EVADE, d3.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual(DiceFace.EVADE, d4.final_dice.dice_face) self.assertEqual(Dice.ADDED, d4.final_dice.dice_origination)
def test_attack_roll_focus_reroll_turn(self): session = myapp.db_connector.get_session() parser = LogFileParser(session) parser.add_line( "* *** sozin Rolls to Attack: [Blank], [Blank], [Blank], [], [], [] ***" ) parser.add_line( "* *** sozin turns Attack Die 1 [Blank] into a [Hit] ***") parser.add_line( "* *** sozin turns Attack Die 2 [Blank] into a [Focus] ***") parser.add_line( "* *** sozin Re-Rolls Attack Die 3 [Blank] and gets a [Focus] ***") parser.add_line("* *** sozin used Focus on Attack Dice ***") parser.add_line("* *** sozin added a Crit ***") parser.run_finite_state_machine() gt = parser.game_tape throw = gt[0] results = throw.results self.assertEqual(4, len(results)) d1 = results[0] self.assertEqual(DiceFace.HIT, d1.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d1.final_dice.dice_origination) d2 = results[1] self.assertEqual(DiceFace.HIT, d2.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d2.final_dice.dice_origination) d3 = results[2] self.assertEqual(DiceFace.HIT, d3.final_dice.dice_face) self.assertEqual(Dice.ROLLED, d3.final_dice.dice_origination) d4 = results[3] self.assertEqual(DiceFace.CRIT, d4.final_dice.dice_face) self.assertEqual(Dice.ADDED, d4.final_dice.dice_origination)
class GameTapeTester(unittest.TestCase): def setUp(self): self.parser = LogFileParser(None) self.parser.read_input_from_file("../logfiles/fsm_test_input.txt") self.parser.run_finite_state_machine() self.game_tape = self.parser.game_tape self.g = Game(None, self.parser.get_players()) for throw_result in self.game_tape: self.g.game_throws.append(throw_result) self.tape = GameTape(self.g) self.tape.score() def testDamage(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] p1_damage = self.g.game_tape.damage(p1) p2_damage = self.g.game_tape.damage(p2) self.assertEqual(0, p1_damage[0]) self.assertEqual(0, p1_damage[1]) self.assertEqual(1, p1_damage[2]) self.assertEqual(1, p1_damage[3]) self.assertEqual(1, p1_damage[4]) self.assertEqual(0, p2_damage[0]) self.assertEqual(0, p2_damage[1]) self.assertEqual(0, p2_damage[2]) self.assertEqual(0, p2_damage[3]) self.assertEqual(0, p2_damage[4]) def testCumulativeStats(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] self.assertEqual(4, self.g.total_reds(p1)) self.assertEqual(3, self.g.total_reds(p2)) p1_init_reds = self.g.game_tape.initial_red_scores(p1) self.assertEqual(5, len(p1_init_reds)) self.assertEqual(0, p1_init_reds[0]) self.assertEqual(-0.8125, p1_init_reds[1]) self.assertEqual(0.125, p1_init_reds[2]) self.assertEqual(0.125, p1_init_reds[3]) self.assertEqual(0.125, p1_init_reds[4]) p1_reds = self.g.game_tape.final_red_scores(p1) self.assertEqual(5, len(p1_reds)) self.assertEqual(0, p1_reds[0]) self.assertEqual(-0.3125, p1_reds[1]) self.assertEqual(0.625, p1_reds[2]) self.assertEqual(0.625, p1_reds[3]) self.assertEqual(0.625, p1_reds[4]) p2_reds = self.g.game_tape.final_red_scores(p2) self.assertEqual(5, len(p2_reds)) self.assertEqual(0, p2_reds[0]) self.assertEqual(0, p2_reds[1]) self.assertEqual(0, p2_reds[2]) self.assertEqual(0.9375, p2_reds[3]) self.assertEqual(1.53125, p2_reds[4]) p1_greens = self.g.game_tape.final_green_scores(p1) self.assertEqual(5, len(p1_greens)) self.assertEqual(0, p1_greens[0]) self.assertEqual(0, p1_greens[1]) self.assertEqual(0, p1_greens[2]) self.assertEqual(1.3125, p1_greens[3]) self.assertEqual(0.625, p1_greens[4]) p2_greens = self.g.game_tape.final_green_scores(p2) print(p2_greens) self.assertEqual(5, len(p2_greens)) self.assertEqual(0, p2_greens[0]) self.assertEqual(0.3125, p2_greens[1]) self.assertEqual(0.75, p2_greens[2]) self.assertEqual(0.75, p2_greens[3]) self.assertEqual(0.75, p2_greens[4]) def testRawSummaryStats(self): p1 = self.g.game_players[0] p2 = self.g.game_players[1] #HITS #totals first self.assertEqual(4, self.g.total_reds(p1)) self.assertEqual(3, self.g.total_reds(p2)) #p1, initial rolls self.assertEqual(1, self.g.unmodified_hits(p1)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_unmodified_hits(p1)) #p2, initial roles self.assertEqual(0, self.g.unmodified_hits(p2)) self.assertEqual((3.0 / 8.0) * 3, self.g.expected_unmodified_hits(p2)) #p1, after rerolls self.assertEqual(1, self.g.total_red_hits_after_rerolls(p1)) self.assertEqual(1.5, self.g.expected_hits_after_rerolls(p1)) #p2, after rerolls self.assertEqual(1, self.g.total_red_hits_after_rerolls(p2)) self.assertEqual((3.0 / 8.0) * 5, self.g.expected_hits_after_rerolls(p2)) #p1, after converts self.assertEqual(2, self.g.total_red_hits_after_converts(p1)) self.assertEqual(1.5, self.g.expected_hits_after_converts(p1)) #p2, after converts self.assertEqual(1, self.g.total_red_hits_after_converts(p2)) self.assertEqual((3.0 / 8.0) * 5, self.g.expected_hits_after_converts(p2)) #CRITS #p1, initial rolls self.assertEqual(1, self.g.unmodified_crits(p1)) self.assertEqual((1.0 / 8.0) * 4, self.g.expected_unmodified_crits(p1)) #p2, initial roles self.assertEqual(1, self.g.unmodified_crits(p2)) self.assertEqual((1.0 / 8.0) * 3, self.g.expected_unmodified_crits(p2)) #p1, after rerolls self.assertEqual(1, self.g.total_red_crits_after_rerolls(p1)) self.assertEqual(.5, self.g.expected_crits_after_rerolls(p1)) #p2, after rerolls self.assertEqual(1, self.g.total_red_crits_after_rerolls(p2)) self.assertEqual((1.0 / 8.0) * 5, self.g.expected_crits_after_rerolls(p2)) #p1, after converts self.assertEqual(1, self.g.total_red_crits_after_converts(p1)) self.assertEqual(.5, self.g.expected_crits_after_converts(p1)) #p2, after converts self.assertEqual(2, self.g.total_red_crits_after_converts(p2)) self.assertEqual((1.0 / 8.0) * 5, self.g.expected_crits_after_converts(p2)) #RED FOCUS #p1, initial rolls self.assertEqual(1, self.g.unmodified_focuses(p1)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_unmodified_focuses(p1)) #p2, initial roles self.assertEqual(0, self.g.unmodified_focuses(p2)) self.assertEqual((2.0 / 8.0) * 3, self.g.expected_unmodified_focuses(p2)) #p1, after rerolls self.assertEqual(1, self.g.total_red_focuses_after_rerolls(p1)) self.assertEqual(4 * (2.0 / 8.0), self.g.expected_focuses_after_rerolls(p1)) #p2, after rerolls self.assertEqual(1, self.g.total_red_focuses_after_rerolls(p2)) self.assertEqual((2.0 / 8.0) * 5, self.g.expected_focuses_after_rerolls(p2)) #p1, after converts self.assertEqual(0, self.g.total_red_focuses_after_converts(p1)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_focuses_after_converts(p1)) #p2, after converts self.assertEqual(0, self.g.total_red_focuses_after_converts(p2)) self.assertEqual((2.0 / 8.0) * 5, self.g.expected_focuses_after_converts(p2)) #RED BLANK #p1, initial blank rolls self.assertEqual(1, self.g.unmodified_blanks(p1)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_unmodified_blanks(p1)) #p2, initial blank rolls self.assertEqual(2, self.g.unmodified_blanks(p2)) self.assertEqual((2.0 / 8.0) * 3, self.g.expected_unmodified_focuses(p2)) #p1, blanks after rerolls self.assertEqual(1, self.g.total_red_blanks_after_rerolls(p1)) self.assertEqual(4 * (2.0 / 8.0), self.g.expected_blanks_after_rerolls(p1)) #p2, after rerolls self.assertEqual(2, self.g.total_red_blanks_after_rerolls(p2)) self.assertEqual((2.0 / 8.0) * 5, self.g.expected_blanks_after_rerolls(p2)) #p1, after converts self.assertEqual(1, self.g.total_red_blanks_after_converts(p1)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_blanks_after_converts(p1)) #p2, after converts self.assertEqual(2, self.g.total_red_blanks_after_converts(p2)) self.assertEqual((2.0 / 8.0) * 5, self.g.expected_blanks_after_converts(p2)) #green dice self.assertEqual(6, self.g.total_greens(p1)) self.assertEqual(4, self.g.total_greens(p2)) #EVADES self.assertEqual(0, self.g.unmodified_evades(p1)) self.assertEqual((3.0 / 8.0) * 6, self.g.expected_unmodified_evades(p1)) self.assertEqual(2, self.g.unmodified_evades(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_unmodified_evades(p2)) #p1, after rerolls self.assertEqual(0, self.g.total_green_evades_after_rerolls(p1)) self.assertEqual((3.0 / 8.0) * 7, self.g.expected_green_evades_after_rerolls(p1)) #p2, after rerolls self.assertEqual(2, self.g.total_green_evades_after_rerolls(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_green_evades_after_rerolls(p2)) #p1, after converts self.assertEqual(4, self.g.total_green_evades_after_converts(p1)) self.assertEqual((3.0 / 8.0) * 7, self.g.expected_green_evades_after_converts(p1)) #p2, after converts self.assertEqual(3, self.g.total_green_evades_after_converts(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_green_evades_after_converts(p2)) #GREEN FOCUSES self.assertEqual(3, self.g.unmodified_green_focuses(p1)) self.assertEqual((2.0 / 8.0) * 6, self.g.expected_unmodified_green_focuses(p1)) #p2, initial roles self.assertEqual(1, self.g.unmodified_green_focuses(p2)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_unmodified_green_focuses(p2)) #p1, after rerolls self.assertEqual(4, self.g.total_green_focuses_after_rerolls(p1)) self.assertEqual(7 * (2.0 / 8.0), self.g.expected_green_focuses_after_rerolls(p1)) #p2, after rerolls self.assertEqual(1, self.g.total_green_focuses_after_rerolls(p2)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_green_focuses_after_rerolls(p2)) #p1, after converts self.assertEqual(0, self.g.total_green_focuses_after_converts(p1)) self.assertEqual((2.0 / 8.0) * 7, self.g.expected_green_focuses_after_converts(p1)) #p2, after converts self.assertEqual(0, self.g.total_green_focuses_after_converts(p2)) self.assertEqual((2.0 / 8.0) * 4, self.g.expected_green_focuses_after_converts(p2)) #GREEN BLANKS self.assertEqual(3, self.g.unmodified_green_blanks(p1)) self.assertEqual((3.0 / 8.0) * 6, self.g.expected_unmodified_green_blanks(p1)) #p2, initial roles self.assertEqual(1, self.g.unmodified_green_blanks(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_unmodified_green_blanks(p2)) #p1, after rerolls self.assertEqual(3, self.g.total_green_blanks_after_rerolls(p1)) self.assertEqual(7 * (3.0 / 8.0), self.g.expected_green_blanks_after_rerolls(p1)) #p2, after rerolls self.assertEqual(1, self.g.total_green_blanks_after_rerolls(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_green_blanks_after_rerolls(p2)) #p1, after converts self.assertEqual(3, self.g.total_green_blanks_after_converts(p1)) self.assertEqual((3.0 / 8.0) * 7, self.g.expected_green_blanks_after_converts(p1)) #p2, after converts self.assertEqual(1, self.g.total_green_blanks_after_converts(p2)) self.assertEqual((3.0 / 8.0) * 4, self.g.expected_green_blanks_after_converts(p2)) def testAttackSetStats(self): self.assertEqual(4, len(self.tape.attack_sets)) aset = self.tape.attack_sets[0] self.assertEqual(-.3125, aset.total_attack_end_luck()) self.assertEqual(.3125, aset.total_defense_end_luck()) aset = self.tape.attack_sets[1] self.assertEqual(.9375, aset.total_attack_end_luck()) self.assertEqual(0.4375, aset.total_defense_end_luck()) aset = self.tape.attack_sets[2] self.assertEqual(0.9375, aset.total_attack_end_luck()) self.assertEqual(1.3125, aset.total_defense_end_luck()) aset = self.tape.attack_sets[3] self.assertEqual(0.59375, aset.total_attack_end_luck()) self.assertEqual(-0.6875, aset.total_defense_end_luck())