Ejemplo n.º 1
0
    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 )
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
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())
Ejemplo n.º 4
0
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() )
Ejemplo n.º 5
0
    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)