コード例 #1
0
ファイル: MEvent1_test.py プロジェクト: CScarame/mafiabot
    def test_basic1(self):

        with open(output_folder + "basic1.out", "w") as f:

            def cast_main(msg):
                print("CAST MAIN: {}".format(msg), file=f)

            def cast_mafia(msg):
                print("CAST MAFIA: {}".format(msg), file=f)

            def send_dm(msg, p_id):
                print("SEND {}: {}".format(p_id, msg), file=f)

            rules = mafiabot.MRules()
            state = mafiabot.MState(cast_main, cast_mafia, send_dm, rules)

            ids = ['1', '2', '3']
            roles = ['TOWN', 'TOWN', 'MAFIA']

            state.start(ids, roles)

            state.vote('1', '3')
            state.vote('2', '3')

            state.close()
コード例 #2
0
ファイル: MEvent1_test.py プロジェクト: CScarame/mafiabot
    def test_fundamentals1(self):

        with open(output_folder + "fundamentals1.out", "w") as f:

            def cast_main(msg):
                print("CAST MAIN: {}".format(msg), file=f)

            def cast_mafia(msg):
                print("CAST MAFIA: {}".format(msg), file=f)

            def send_dm(msg, p_id):
                print("SEND {}: {}".format(p_id, msg), file=f)

            rules = mafiabot.MRules()
            state = mafiabot.MState(cast_main, cast_mafia, send_dm, rules)

            ids = ['1', '2', '3']
            roles = ['TOWN', 'TOWN', 'MAFIA']

            state.start(ids, roles)

            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)
            self.assertEqual(len(state.players), 3)

            state.vote('1', '2')

            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)

            state.vote('1', None)
            state.vote('2', '2')

            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)

            state.vote('2', 'NOTARGET')
            state.vote('1', '2')

            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)
            self.assertTrue(state.active)

            state.vote('3', '2')

            time.sleep(.1)
            self.assertFalse(state.active)

            state.close()
コード例 #3
0
ファイル: MEvent1_test.py プロジェクト: CScarame/mafiabot
    def evenOddTest(ut, f, start_night, even, should_be_night):
        def cast_main(msg):
            print("CAST MAIN: {}".format(msg), file=f)

        def cast_mafia(msg):
            print("CAST MAFIA: {}".format(msg), file=f)

        def send_dm(msg, p_id):
            print("SEND {}: {}".format(p_id, msg), file=f)

        rules = mafiabot.MRules()
        rules["start_night"] = start_night
        print(rules, file=f)
        state = mafiabot.MState(cast_main, cast_mafia, send_dm, rules)

        if even:
            ids = ['1', '2', '3', '4']
            roles = ['TOWN', 'TOWN', 'MAFIA', 'TOWN']
        else:
            ids = ['1', '2', '3']
            roles = ['TOWN', 'TOWN', 'MAFIA']

        state.start(ids, roles)
        time.sleep(.1)
        if not should_be_night:
            ut.assertEqual(state.phase, mafiabot.MPhase.DAY)
            state.vote('1', 'NOTARGET')
            state.vote('2', 'NOTARGET')

        time.sleep(.1)
        ut.assertEqual(state.phase, mafiabot.MPhase.NIGHT)

        if even:
            state.mtarget('3', '4')
        else:
            state.mtarget('3', 'NOTARGET')

        state.vote('1', '3')
        state.vote('2', '3')

        time.sleep(.1)
        ut.assertEqual(state.active, False)

        state.close()
コード例 #4
0
ファイル: MEvent1_test.py プロジェクト: CScarame/mafiabot
    def test_doctor1(self):

        with open(output_folder + "doctor1.out", "w") as f:

            def cast_main(msg):
                print("CAST MAIN: {}".format(msg), file=f)

            def cast_mafia(msg):
                print("CAST MAFIA: {}".format(msg), file=f)

            def send_dm(msg, p_id):
                print("SEND {}: {}".format(p_id, msg), file=f)

            rules = mafiabot.MRules()
            rules["start_night"] = "ON"
            state = mafiabot.MState(cast_main, cast_mafia, send_dm, rules)

            ids = ['1', '2', '3']
            roles = ['TOWN', 'DOCTOR', 'STRIPPER']

            state.start(ids, roles)

            state.mtarget('3', '2')
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.NIGHT)
            self.assertEqual(len(state.players), 3)

            state.target('3', 'NOTARGET')
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.NIGHT)
            self.assertEqual(len(state.players), 3)

            state.target('2', '2')
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)
            self.assertEqual(len(state.players), 3)

            state.timer()
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.NIGHT)
            self.assertEqual(len(state.players), 3)

            state.target('2', '3')
            state.mtarget('3', '1')
            state.target('2', '1')
            state.target('3', 'NOTARGET')
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.DAY)
            self.assertEqual(len(state.players), 3)

            state.timer()
            time.sleep(.1)
            self.assertEqual(state.phase, mafiabot.MPhase.NIGHT)
            self.assertEqual(len(state.players), 3)

            state.mtarget('3', '2')
            state.target('2', '2')
            state.target('3', '2')
            time.sleep(.1)
            self.assertFalse(state.active)

            state.close()