コード例 #1
0
def main(argv):
    loading_width = 50
    scores = []
    start = time.time()
    for i in range(FLAGS.n_games):
        controller = GameController(gameplayMode=FLAGS.mode,
                                    optimizer=FLAGS.opt,
                                    depth=FLAGS.depth,
                                    display_board=FLAGS.display_board)
        grid = controller.run(moveDelay=FLAGS.move_delay)
        scores.append(max(grid))

    end = time.time() - start

    print('Highest score: {}'.format(0 if len(scores) == 0 else max(scores)))
    d = {}
    for i in scores:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    for i in sorted(list(d)):
        print('{}: {}'.format(i, d[i] / len(scores)))
    print('Average time per game: {} seconds'.format(
        end / (1 if FLAGS.n_games == 0 else FLAGS.n_games)))
コード例 #2
0
class RunController:
    """
    This class coordinates the entire game and transfers data between different parts
    This file must be run to start the game
    """

    game: GameController = None
    gph: Graphics = None

    # Initialize objects
    def __init__(self, show_graphics: bool = True):

        self.running: bool = True

        self.game = GameController(self)
        RunController.game = self.game

        self.gph = Graphics(self, self.game.map, self.game.player)
        RunController.gph = self.gph

        self.game_events: list = []
        self.show_graphics: bool = show_graphics
        self.graphics_events: deque = deque([])

    # Update each frame
    def update(self):
        game_events = []
        if self.graphics_events:
            game_events = self.game.event(self.graphics_events.popleft())
        game_events.extend(self.game.update())

        self.graphics_events.extend(self.gph.update(game_events))

        if game_events is not None:
            for e in game_events:
                if e.type() == 'print':
                    pass
                    # print text output also to the console
                    # print(e.get_value('text') if 'text' in e else e.value())

    # Begin the game loop
    def run(self):
        # intro screen (or menu?)
        out = None
        self.gph.intro_start()
        while out is None:
            out = self.gph.intro_update()

        # main game loop
        while self.running:
            self.update()

        pygame.quit()

    # Exit the program
    def quit(self):
        self.running = False
        self.game.quit()
        self.gph.quit()
コード例 #3
0
def select_robber_callback():
    robot_list_lock.acquire()
    try:
        for robot in robot_list:
            robot.is_police_chase_ongoing = True
        logger.info("Game starting. Selecting robber.")
        GameController.select_robber(robot_list, GameDifficulty.EASY)
    finally:
        robot_list_lock.release()
コード例 #4
0
 def setUp(self):
     self.controller = GameController()
     self.controller.show()
     self.xybh = [
         (130, 180, 75, 23), (210, 180, 75, 23), (290, 180, 75, 23),
         (370, 180, 75, 23), (450, 180, 75, 23), (130, 150, 75, 23),
         (210, 150, 75, 23), (290, 150, 75, 23), (370, 150, 75, 23),
         (450, 150, 75, 23), (130, 120, 75, 23), (210, 120, 75, 23),
         (290, 120, 75, 23), (370, 120, 75, 23), (450, 120, 75, 23)
     ]
コード例 #5
0
    def __init__(self, show_graphics: bool = True):

        self.running: bool = True

        self.game = GameController(self)
        RunController.game = self.game

        self.gph = Graphics(self, self.game.map, self.game.player)
        RunController.gph = self.gph

        self.game_events: list = []
        self.show_graphics: bool = show_graphics
        self.graphics_events: deque = deque([])
コード例 #6
0
ファイル: gameview.py プロジェクト: tcafxc/connectfour
class GameView:
	def __init__(self):
		self.game_over = False
		self.__game_controller = GameController()
		self.game_vars = self.__game_controller.start_game()
		self.available_columns = self.game_vars['available_columns']
		self.current_player = self.game_vars['current_player']
		self.__gui = GameUI()
		self.__gui.display(self.game_vars)

	def make_move(self,move):
		self.game_vars = self.__game_controller.player_move(move)
		self.number_of_moves = self.game_vars['number_of_moves']
		self.current_player = self.game_vars['current_player']
		if self.game_vars['message']:
			self.game_over = True
		self.__gui.display(self.game_vars)
コード例 #7
0
ファイル: gameview.py プロジェクト: tcafxc/connectfour
	def __init__(self):
		self.game_over = False
		self.__game_controller = GameController()
		self.game_vars = self.__game_controller.start_game()
		self.available_columns = self.game_vars['available_columns']
		self.current_player = self.game_vars['current_player']
		self.__gui = GameUI()
		self.__gui.display(self.game_vars)
コード例 #8
0
ファイル: main.py プロジェクト: gabrielepanda/zeroids
def main():
    resolution = (1200, 800)
    max_fps = 50
    default_backcolor = (0, 0, 0)
    pygame.init()

    screen = pygame.display.set_mode(resolution)
    clock = pygame.time.Clock()

    filename = os.path.normpath("assets/images/stars.jpg")
    image = pygame.image.load(filename)
    background_image = image.subsurface((0,0), (resolution[0], resolution[1])).copy()
    background_image.convert()
    background_image.set_alpha(127)

    main_event_queue = EventQueue()
    clock = pygame.time.Clock()
    context_data = { "clock": clock,
                     "resolution": resolution,
                     "screen": screen,
                    }
    game_context = GameContext(context_data)
    game_controller = GameController(main_event_queue, game_context)
    loop = True
    clock.tick(max_fps)
    clock.tick(max_fps)

    # intro module
    sigla.intro_title(screen, game_context)
    pygame.time.wait(500)
    sigla.fade_to_black(resolution, screen)
    sigla.personaggi_entrano_in_scena(screen, game_context)
    sigla.fade_to_black(resolution, screen)

    while loop:
        loop = main_event_queue.handle_events()
        background_change, background, screen_elements = game_controller.update()
        screen.fill(default_backcolor)
        screen.blit(background_image, (0,0))
        screen_elements.draw(screen)
        pygame.display.flip()
        clock.tick(max_fps)
コード例 #9
0
ファイル: regression.py プロジェクト: leifktaylor/modeling
def current_room_test():
    gc = GameController()
    gc.goc.add_room('gameobjects/room/template.rm')
    # Start server on GC
    for id, lf in gc.goc.lifeforms.items():
        print(lf.current_room)

    s = multiprocessing.Process(target=gc.run, name="Run", args=())
    s.start()
    time.sleep(2)
    c = client.GameClient()
    c.login()
    c.send('evaluate', 'gameobjects[{0}].current_room'.format(c.id))
    s.terminate()
    s.join()
コード例 #10
0
ファイル: test.py プロジェクト: kmatsuuraHMC/pocketautochess
def main():
    gamecon = GameController()
    gamecon.player1.key = 5
    gamecon.player2.key = 6
    for i in range(2):
        for j in range(3):
            filename = "sample_input/p{0}d{1}.json".format(i + 1, j + 1)
            with open(filename) as f:
                data = json.load(f)
            gamecon.deploy_minions(data)
    gamecon.execute_game()
    print("win:{}".format(gamecon.game.win))
コード例 #11
0
ファイル: regression.py プロジェクト: leifktaylor/modeling
def ai_gambits():
    print('-------------------------')
    print('Parse simple precondition: stat HP>10')
    gc = GameController()
    go, id = gc.goc.add_gameobject('gameobjects/regression/dummy.lfm')
    print(go.ai)
    print(go.aic.data)
    aic = go.aic
    r = aic.check_condition(['stat', 'HP<10'], go)
    print(r)
    assert r is False
    r = aic.check_condition(['stat', 'MND>20'], go)
    print(r)
    assert r is True
    r = aic.check_condition(['stat', 'MP>100'], go)
    print(r)
    assert r is False
    r = aic.check_condition(['stat', 'MAXHP>11'], go)
    print(r)
    assert r is True
    r = aic.check_condition(['stat', 'SPD<20'], go)
    print(r)
    assert r is True
コード例 #12
0
def run_camera():
    logger.debug("Camera running.")
    global city_builder
    global robot_list_lock

    # Set up camera
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

    warm_up_count = 0
    while warm_up_count < 2:
        _, frame = cap.read()
        time.sleep(1)
        warm_up_count += 1

    # Start capturing frames
    while True:
        _, frame = cap.read()

        lead_points, trail_points = ColorDetection.get_blue_and_green_points_from_frame(
            frame)

        if len(lead_points) == len(trail_points):
            paired_points = PointPairing.pair_point_lists(
                lead_points, trail_points, 20)
            # Points have been paired. For each point, select the appropriate robot.
            # TODO: are the points really paired ok?
            # Access robot_list
            robot_list_lock.acquire()
            try:
                if len(robot_list) > 0:
                    for robot in robot_list:
                        logger.debug(robot.robot_name + " on street " +
                                     robot.current_street.street_name)
                        if robot.role == RobotRole.POLICE:
                            cv2.putText(
                                frame, "Police",
                                (robot.leading_point.x, robot.leading_point.y),
                                0, 0.4, (0, 0, 255), 1, cv2.LINE_AA)
                            if GameController.is_robber_in_range(
                                    robot, robot_list):
                                # Game ended
                                gui_controller.write_text_in_console_box(
                                    "Police has caught the robber!")
                                sys.exit(0)
                        if robot.role == RobotRole.ROBBER:
                            cv2.putText(
                                frame, "Robber",
                                (robot.leading_point.x, robot.leading_point.y),
                                0, 0.4, (0, 0, 255), 1, cv2.LINE_AA)
                        closest_point = robot.leading_point.get_nearest_point(
                            20, list(paired_points.keys()))
                        if closest_point is None:
                            logger.warning("Robot " + robot.robot_name +
                                           " has been removed from the game!")
                            robot_list.remove(robot)
                            pass
                        else:
                            logger.debug("new closest point! " +
                                         str(closest_point.x) + "," +
                                         str(closest_point.y))
                            robot.leading_point = closest_point
                            # Get corresponding paired point for the closest point
                            robot.trailing_point = paired_points[closest_point]
                            if robot.trailing_point is None:
                                logger.fatal(
                                    "Cannot correctly pair points for robot " +
                                    robot.robot_name)
                            else:
                                logger.debug("New points for robot " +
                                             str(robot.robot_name) + ": " +
                                             str(robot.leading_point.x) +
                                             ", " +
                                             str(robot.leading_point.y) + ";" +
                                             str(robot.trailing_point.x) +
                                             ", " +
                                             str(robot.trailing_point.y))
                                for robot_to_check in robot_list:
                                    if robot_collision_controller.is_robot1_in_collision_with_robot2(
                                            robot, robot_to_check):
                                        logger.debug(
                                            "Robot " + robot.robot_name +
                                            " is on collision course with " +
                                            robot_to_check.robot_name)
                                        robot.is_on_collision_course = True
                                    else:
                                        robot.is_on_collision_course = False

                                robber_street_name = GameController.get_robber_street_name(
                                    robot_list)

                                robot.move_robot_to_next_position(
                                    command_controller, city_builder,
                                    robber_street_name)
                else:
                    logger.info("No robots contained in list.")
            finally:
                robot_list_lock.release()
        else:
            logger.debug(
                "Length of leading points and length of trailing points not equal. Error occurred."
            )

        cv2.waitKey(30)

        traffic_light_draw_utility.draw_traffic_light_status(frame)
        # city_builder.draw_streets_on_opencv_frame(frame)
        gui_controller.update_gui(frame)

    cap.release()
    cv2.destroyAllWindows()
コード例 #13
0
"""
Created on 17.11.2017

@author: Michael Borko <*****@*****.**>, Hans Brabenetz <*****@*****.**>
@version: 20171117

@description: Implementation eines einfachen Spiels
"""

from gamecontroller import GameController
from PyQt5 import QtCore, QtGui, QtWidgets
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    controller = GameController()
    controller.show()
    sys.exit(app.exec_())
コード例 #14
0
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()
        self.xybh = [
            (130, 180, 75, 23), (210, 180, 75, 23), (290, 180, 75, 23),
            (370, 180, 75, 23), (450, 180, 75, 23), (130, 150, 75, 23),
            (210, 150, 75, 23), (290, 150, 75, 23), (370, 150, 75, 23),
            (450, 150, 75, 23), (130, 120, 75, 23), (210, 120, 75, 23),
            (290, 120, 75, 23), (370, 120, 75, 23), (450, 120, 75, 23)
        ]

    def tearDown(self):
        del self.controller
        del self.xybh

    '''
    Test the GUI in its default state
    '''

    def test_layoutButton0(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.buttons[0].geometry(),
                         QtCore.QRect(130, 180, 75, 23))

    def test_layoutButton1(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[1]
        self.assertEqual(self.controller.view.buttons[1].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton2(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[2]
        self.assertEqual(self.controller.view.buttons[2].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton3(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[3]
        self.assertEqual(self.controller.view.buttons[3].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton4(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[4]
        self.assertEqual(self.controller.view.buttons[4].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton5(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[5]
        self.assertEqual(self.controller.view.buttons[5].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton6(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[6]
        self.assertEqual(self.controller.view.buttons[6].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton7(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[7]
        self.assertEqual(self.controller.view.buttons[7].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton8(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[8]
        self.assertEqual(self.controller.view.buttons[8].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton9(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[9]
        self.assertEqual(self.controller.view.buttons[9].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton10(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[10]
        self.assertEqual(self.controller.view.buttons[10].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton11(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[11]
        self.assertEqual(self.controller.view.buttons[11].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton12(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[12]
        self.assertEqual(self.controller.view.buttons[12].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton13(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[13]
        self.assertEqual(self.controller.view.buttons[13].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton14(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[14]
        self.assertEqual(self.controller.view.buttons[14].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutAllButtons(self):
        '''Test the GUI in its default state'''
        for i in range(15):
            x, y, b, h = self.xybh[i]
            self.assertEqual(self.controller.view.buttons[i].geometry(),
                             QtCore.QRect(x, y, b, h))

    def test_layoutLabel(self):
        self.assertEqual(self.controller.view.label.geometry(),
                         QtCore.QRect(130, 60, 391, 31))

    def test_layoutLabel2(self):
        self.assertEqual(self.controller.view.label_2.geometry(),
                         QtCore.QRect(20, 240, 41, 16))

    def test_layoutLabel3(self):
        self.assertEqual(self.controller.view.label_3.geometry(),
                         QtCore.QRect(20, 210, 41, 16))

    def test_layoutLabel4(self):
        self.assertEqual(self.controller.view.label_4.geometry(),
                         QtCore.QRect(20, 180, 41, 16))

    def test_layoutLabel5(self):
        self.assertEqual(self.controller.view.label_5.geometry(),
                         QtCore.QRect(20, 150, 41, 16))

    def test_layoutLabel6(self):
        self.assertEqual(self.controller.view.label_6.geometry(),
                         QtCore.QRect(20, 120, 41, 16))

    def test_lineEdit_0(self):
        self.assertEqual(self.controller.view.lineEdit_0.geometry(),
                         QtCore.QRect(70, 120, 31, 20))

    def test_lineEdit_1(self):
        self.assertEqual(self.controller.view.lineEdit_1.geometry(),
                         QtCore.QRect(70, 150, 31, 20))

    def test_lineEdit_2(self):
        self.assertEqual(self.controller.view.lineEdit_2.geometry(),
                         QtCore.QRect(70, 180, 31, 20))

    def test_lineEdit_3(self):
        self.assertEqual(self.controller.view.lineEdit_3.geometry(),
                         QtCore.QRect(70, 210, 31, 20))

    def test_lineEdit_4(self):
        self.assertEqual(self.controller.view.lineEdit_4.geometry(),
                         QtCore.QRect(70, 240, 31, 20))

    def test_pushButton_Neu(self):
        self.assertEqual(self.controller.view.pushButton_Neu.geometry(),
                         QtCore.QRect(210, 240, 75, 23))

    def test_pushButton_End(self):
        self.assertEqual(self.controller.view.pushButton_End.geometry(),
                         QtCore.QRect(370, 240, 75, 23))

    def test_defaults0(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_2.text(), "Spiele")

    def test_defaults1(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_3.text(), "gesamt")

    def test_defaults2(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_4.text(), "falsch")

    def test_defaults3(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_5.text(), "korrekt")

    def test_defaults4(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_6.text(), "offen")

    def test_defaults5(self):
        '''Test the GUI in its default state'''
        self.assertEqual(
            self.controller.view.label.text(),
            "<html><head/><body><p align=\"center\">Drücken Sie die Buttons in aufsteigender Richtung</p></body></html>"
        )

    def test_defaults6(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.pushButton_Neu.text(), "Neu")

    def test_defaults7(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.pushButton_End.text(), "Ende")

    def test_defaults8(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.Dialog.windowTitle(), "MyGame")

    def test_defaults9(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_4.text(), "1")

    def test_defaults10(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_0.text(), "15")

    def test_defaults11(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_1.text(), "0")

    def test_defaults12(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_2.text(), "0")

    def test_defaults13(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_3.text(), "0")

    def test_defaultData1(self):
        self.assertEqual(self.controller.model.isCorrect, 0)

    def test_defaultData2(self):
        self.assertEqual(self.controller.model.isOpen, 15)

    def test_defaultData3(self):
        self.assertEqual(self.controller.model.isWrong, 0)

    def test_defaultData4(self):
        self.assertEqual(self.controller.model.isTotal, 0)

    def test_defaultData5(self):
        self.assertEqual(self.controller.model.Ngame, 1)

    def test_defaults14(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[0].text()) in range(15))

    def test_defaults15(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[1].text()) in range(15))

    def test_defaults16(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[2].text()) in range(15))
        # def test_defaults17(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[3].text()) in range(15))

    def test_defaults18(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[4].text()) in range(15))
        # def test_defaults19(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[5].text()) in range(15))

    def test_defaults20(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[6].text()) in range(15))
        # def test_defaults21(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[7].text()) in range(15))

    def test_defaults22(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[8].text()) in range(15))
        # def test_defaults23(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[9].text()) in range(15))

    def test_defaults24(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[10].text()) in range(15))
        # def test_defaults25(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[11].text()) in range(15))

    def test_defaults26(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[12].text()) in range(15))
        # def test_defaults27(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[13].text()) in range(15))

    def test_defaults28(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[14].text()) in range(15))

    def test_defaultsAllButtons(self):
        '''Test the GUI in its default state'''
        for i in range(15):
            self.assertTrue(
                int(self.controller.view.buttons[i].text()) in range(15))

    def test_isRandom(self):
        '''Test the GUI in its default state'''
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        listCompUp = [i for i in range(15)]
        #print(listCompUp)
        self.assertTrue(list0 != listCompUp)

    def test_isRandom1(self):
        '''Test the GUI in its default state'''
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        listCompUp = [i for i in range(14, -1, -1)]
        #print(listCompUp)
        self.assertTrue(list0 != listCompUp)

    def test_isUniqueNumbers(self):
        '''Test the GUI in its default state'''
        set0 = set()
        for i in range(15):
            set0.add(int(self.controller.view.buttons[i].text()))
        #print(set0)
        self.assertTrue(len(set0) == 15)
コード例 #15
0
from flask import Flask, request, session, escape, jsonify
import json
from gamecontroller import GameController

# declare variable

# main body of the game
game = GameController()
# waiting user of the game
user_list = []
# generated_key_list
generated_key_list = []
generated_key_number = 0
# matchした人
match = -1
# matching中のペア
matching = []

# print a nice greeting.


def say_hello(username="******"):
    return '<p>Hello %s!</p>\n' % username


# some bits of text for the page.
header_text = '''
    <html>\n<head> <title>Pocket Auto Chess</title> </head>\n<body>'''
instructions = '''
    <p><em>Hint</em>: This is a RESTful web service!</p>\n'''
home_link = '<p><a href="/">Back</a></p>\n'
コード例 #16
0
ファイル: runner.py プロジェクト: PhilBeaudoin/empirestate
from resources import Resources, Firms
from board import Board
import numpy

def printHisto(name, bins, range, stats):
  print name
  histos = [ numpy.histogram(turn, bins=bins, range=range)
             for turn in stats[name] ]
  print "  " + str([int(h) for h in histos[0][1]])
  for histo in histos:
    print "  " + str(list(histo[0]))

stats = []
actions = []
for i in xrange(100):
  gc = GameController(Board())
  gc.playGame()
  stats.append(gc.statistics)
  actions.append(gc.actionsOfGame)

actionNames = ['getCard-factory', 'getCard-workforce', 'getCard-equipment',
               'getCard-plusLevel', 'getCard-loanGoods', 'getCard-loan',
               'getCard-moneyForLevel', 'getCard-bonusToken', 'getCard-upgrade',
               'getCard-action', 'getCard-finalMoney',
               'getCard', 'getMoneyOnGoods', 'invest',
               'build', 'sellShare', 'payLoan', 'skip']
actionStats = { name: [[] for i in range(6)] for name in actionNames }
for game in actions:
  for turn in game:
    turnIndex = turn['turnIndex']
    turnStats = { name: 0 for name in actionNames }
コード例 #17
0
ファイル: regression.py プロジェクト: leifktaylor/modeling
def gamecontroller_test_basic():
    print('-----------------------')
    print(
        'Test 1 - Create GC, Add a room, Login player and verify player is added properly'
    )
    print('Instantiating GameController')
    gc = GameController()
    # Start server on GC
    s = multiprocessing.Process(target=gc.run, name="Run", args=())
    s.start()
    time.sleep(2)
    # Create gameclient and login
    c = client.GameClient()
    c.login()
    time.sleep(1)
    # Verify that playerid on Client and id in GOC match
    print(
        'Verifying that player Lifeform created in GOC and that it matches client charactername'
    )
    clientid = c.id
    response = c.send('evaluate', 'gameobjects[{0}].name'.format(clientid))
    assert response['response']['message'] == c.charactername
    response = c.send('evaluate', 'gameobjects[{0}].player'.format(clientid))
    print('Is player: {0}'.format(response['response']['message']))
    response = c.send('evaluate', 'gameobjects[{0}].ai'.format(clientid))
    print('AI: {0}'.format(response['response']['message']))
    print('Character created successfully!')
    time.sleep(1)
    print('Attempting to login again with same character, should NOT succeed')
    failed = False
    try:
        c.login()
    except ServerResponseError:
        failed = True
        print('Re-Login failed as expected!')
    assert failed is True
    time.sleep(1)

    print('------------------------')
    print('Test 2 - Player logout')
    print(
        'This test will now logout the player and confirm he has been removed from the GOC'
    )
    playername = c.send('evaluate', 'playernames')['response']['message'][0]
    print('{0} currently logged in, logging out...'.format(playername))
    c.logout()
    time.sleep(1)
    playername = c.send('evaluate', 'playernames')['response']['message']
    if len(playername) is not 0:
        raise RuntimeError('Player not successfully logged out')
    print('Player logged out and removed from GOC successfully!')
    print('Attempting to logout again, should not crash server...')
    failed = False
    try:
        c.logout()
    except ServerResponseError:
        failed = True
        print('Re-Logout failed as expected!')
    assert failed is True
    print('Second logout attempted failed as expected')
    time.sleep(1)
    s.terminate()
    s.join()

    print('---------------------------')
    print('Test 3 - Rapid login logout')
    # Constants #
    amount = 200

    gc = GameController()
    gc.goc._gameobjects = {}
    s = multiprocessing.Process(target=gc.run, name="Run", args=())
    s.start()
    time.sleep(2)
    # Create gameclient and login
    c = client.GameClient()
    print('Rapidly logging in and out 200 times')
    for i in range(0, amount):
        c.login()
        c.logout()
    print('Verifying no gameobjets in GOC')
    assert gc.goc.gameobjects == {}
    print('Success! No hero zombies left over!')
    s.terminate()
    s.join()

    print('-----------------------')
    print('Test 4 - Coordinates, verify coordinate updates')
    print('Instantiating GameController')
    gc = GameController()
    gc.goc.add_room('gameobjects/room/template.rm')
    # Start server on GC
    s = multiprocessing.Process(target=gc.run, name="Run", args=())
    s.start()
    time.sleep(2)
    c = client.GameClient()
    c.login()
    c.send('evaluate', 'gameobjects[{0}].current_room'.format(c.id))
    s.terminate()
    s.join()
コード例 #18
0
from controllers import PlayerController
from controllers import TournamentController
from gamecontroller import GameController

if __name__ == "__main__":
    players = PlayerController()
    tournament = TournamentController()
    start = GameController(players, tournament)
コード例 #19
0
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()

    def tearDown(self):
        del self.controller

    '''
    Now lets have fun, lets play
    Test the GUI in game...
    '''

    def test_ClickButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 1)

    def test_ClickButtonNum01(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 1)
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 1
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 2)

    def test_ClickAllButtonsCorrectly(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isCorrect == g + 1)

    def test_ClickAllButtonsCorrectly2(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isTotal == g + 1)

    def test_ClickAllButtonsCorrectly3(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isOpen == 14 - g)

    def test_ClickAllButtonsCorrectly4(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isWrong == 0)

    def test_ClickAllButtonsCorrectly5(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.Ngame == 1)

    def test_ClickWrongButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[(p[0] + 1) % 15].click()
        self.assertTrue(self.controller.model.isCorrect == 0)
        self.assertTrue(self.controller.model.isWrong == 1)
        self.assertTrue(self.controller.model.isOpen == 15)
        self.assertTrue(self.controller.model.isTotal == 1)
        self.assertTrue(self.controller.model.Ngame == 1)

    def test_Click30TimesWrongButton(self):
        ''' Test the GUI in game '''
        for e in range(30):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            #print("Button with 0 is ", str(p))
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == e + 1)
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isTotal == e + 1)
            self.assertTrue(self.controller.model.Ngame == 1)

    def test_Click3TimesWrongThenStartaNewErrorFreeGame(self):
        ''' Test the GUI in game '''
        for e in range(3):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            #print("Button with 0 is ", str(p))
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == e + 1)
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isTotal == e + 1)
            self.assertTrue(self.controller.model.Ngame == 1)
        self.controller.view.pushButton_Neu.click()
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isOpen == 14 - g)
            self.assertTrue(self.controller.model.isCorrect == g + 1)
            self.assertTrue(self.controller.model.isWrong == 0)
            self.assertTrue(self.controller.model.isTotal == g + 1)
            self.assertTrue(self.controller.model.Ngame == 2)

    def test_Click10timesNewGameOnly(self):
        ''' Test the GUI in game '''
        for g in range(10):
            self.controller.view.pushButton_Neu.click()
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == 0)
            self.assertTrue(self.controller.model.isTotal == 0)
            self.assertTrue(self.controller.model.Ngame == g + 2)

    def test_DispClickButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "1")

    def test_DispClickButtonNum01(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "1")
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 1
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "2")

    def test_DispClickAllButtonsCorrectly(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             g + 1)

    def test_DispClickAllButtonsCorrectly2(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             g + 1)

    def test_DispClickAllButtonsCorrectly3(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             14 - g)
            self.assertEqual(int(self.controller.view.lineEdit_2.text()), 0)
            self.assertEqual(int(self.controller.view.lineEdit_4.text()), 1)

    def test_DispClickWrongButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[(p[0] + 1) % 15].click()
        self.assertEqual(int(self.controller.view.lineEdit_0.text()), 15)  #op
        self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                         0)  #correct
        self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                         1)  #wrong
        self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                         1)  #total
        self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                         1)  #Ngame

    def test_DispClick30TimesWrongButton(self):
        ''' Test the GUI in game '''
        for e in range(30):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             e + 1)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             e + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             1)  #Ngame

    def test_DispClick3TimesWrongThenStartaNewErrorFreeGame(self):
        ''' Test the GUI in game '''
        for e in range(3):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             e + 1)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             e + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             1)  #Ngame
        self.controller.view.pushButton_Neu.click()
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             14 - g)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             g + 1)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             0)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             g + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             2)  #Ngame

    def test_DispClick10timesNewGameOnly(self):
        ''' Test the GUI in game '''
        for g in range(10):
            self.controller.view.pushButton_Neu.click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             0)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             0)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             g + 2)  #Ngame
コード例 #20
0
ファイル: playgame.py プロジェクト: grof/py-blackjack
def play_game():

    game = GameController()
    game.prep_player()

    while game.ask_play():

        game.ask_player_bet()
        game.prep_dealer()
        game.hand_to_player()
        game.hand_to_dealer()

        # we may have a winner right with the initial cards
        initial_outcome = game.check_initial_hands()
        if initial_outcome != 'game goes on':
            game.process_blackjack(initial_outcome)
            game.collect_used_cards()
            continue

        game.do_player_turn()
        # if player busts, dealer wins and does not even
        # have to show his hidden card
        player_status = game.check_player()
        if player_status == 'player_busted':
            game.handle_game_outcome('dealer')
            game.collect_used_cards()
            continue

        game.do_dealer_turn()
        dealer_status = game.check_dealer()
        if dealer_status == 'dealer_busted':
            game.handle_game_outcome('player')
            game.collect_used_cards()
            continue

        # neither dealer nor player busted so
        # let's find the winner based on totals
        outcome = game.find_winner()
        game.handle_game_outcome(outcome)
        game.collect_used_cards()

    # player answered 'no' to the play again question
    print("\nYou go home with $" + str(game.player.bankroll))
    print("Thanks for playing!")
コード例 #21
0
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()

    def tearDown(self):
        del self.controller

    '''
    Now lets test the more difficult stuff
    EK, Test the GUI in game...
    '''

    def test_hasFocus(self):
        '''Test the GUI in its default state'''
        # when we start the game, has Button '0' the focus?
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 0:
                self.assertTrue(self.controller.view.buttons[i].hasFocus())

    def test_hasFocus1(self):
        #after successfully clicing 5 times, does button 4 have the focus?
        for g in range(5):
            p = [
                i for i in range(15)
                if (int(self.controller.view.buttons[i].text()) == g)
            ]
            #self.controller.show()
            self.controller.view.buttons[p[0]].click()
            #self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 4:
                self.assertTrue(self.controller.view.buttons[i].hasFocus())

    def test_hasFocus2(self):
        # clicking the right buttons all along
        # when we start the game, has Button '0' the focus and each correctly clicked button afterwards has focus ?
        for g in range(
                14
        ):  #the 14th button will be disabled immediately so cannot have focus anymore
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #self.controller.show()
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus3(self):
        # clicking whatever buttons all along
        # when we play the game, each clicked button has focus ?
        for g in range(
                50
        ):  #Attention, somewhen this might eventually fail bec a shuffle will come in its way
            self.controller.show(
            )  # show is needed for so many clicks. Until ~range 20 it will do without show
            self.controller.view.buttons[g % 15].click()
            self.assertTrue(self.controller.view.buttons[g % 15].hasFocus())

    def test_hasFocus4(self):
        # clicking whatever buttons all along
        # when we play the game, each clicked button has focus ?
        #self.controller.view.timer.stop()
        for g in range(50):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g % 15
            ]
            self.controller.show(
            )  # show is needed for so many clicks. Until ~range 20 it will do without show
            self.controller.view.buttons[p[0]].click()
            #time.sleep(1)
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus5(self):
        # Are all buttons without focus after successful 7 clicks, a reShuffle and a successful finish
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        self.controller.reshuffle()
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].hasFocus() == False)

    def test_hasFocus6(self):
        # After a reShuffle when Button 6 had focus before, does it still have focus afterwards?
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        self.controller.reshuffle()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus7(self):
        # Are all buttons with focus during successful 7 clicks, a reShuffle and a successful continuation
        # but the very last button looses its focus when clicked since it gets disable immediaely!
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        self.controller.reshuffle()
        for g in range(6, 14):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        for g in range(14, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(
                self.controller.view.buttons[p[0]].hasFocus() == False)

    def test_isDisabled(self):
        # is button 0 disabled after button 0 and button 1 was hitted successfully?
        for g in range(2):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 0:
                self.assertTrue(
                    self.controller.view.buttons[i].isEnabled() == False)

    def test_isDisabled1(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # all remaining buttons are still enabled
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)

    def test_isDisabled2(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # not button 7 is hitted correctly now
        # is Button 6 now disabled?
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(7, 8):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)

    def test_isDisabled3(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # not button 10 is hitted in error
        # is Button 6 still enabled?
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(10, 11):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)

    def test_isDisabled4(self):
        # Are all buttons disabled after a successful run?
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].isEnabled() == False)

    def test_isDisabled5(self):
        # Are all buttons disabled after a successful 7 clicks, a reShuffle and a successful finish
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        self.controller.reshuffle()
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].isEnabled() == False)

    '''
    EK is there a timer to reshuffle the numbers in game?
    '''

    def test_isthereaTimer(self):
        self.assertIsNone(self.controller.view.timer.stop())

    def test_Timer1(self):
        self.assertTrue(self.controller.view.timer.interval() == 2000)

    def test_Timer2(self):
        self.assertIsNone(self.controller.view.timer.start())

    def test_Timer3(self):
        # does the timer call reShuffle and does reShuffle really shuffle?
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        self.assertIsNone(self.controller.view.timer.setInterval(1))
        #self.controller.reShuffle()
        self.controller.show()
        list1 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list1)
        #print("Intervall = ", str(self.controller.view.timer.interval()))
        self.assertTrue(list0 != list1)

    def test_Timer4(self):
        self.assertIsNone(self.controller.view.timer.setInterval(2000))

    def test_Timer5(self):
        self.assertIsNone(self.controller.view.timer.start())
コード例 #22
0
 def setUp(self):
     self.controller = GameController()
     self.controller.show()
コード例 #23
0

def stop_screen(screen):
    curses.echo()
    curses.nocbreak()
    screen.keypad(False)
    curses.endwin()


def exit_app(ecode, screen):
    stop_screen(screen)
    sys.exit(ecode)


if __name__ == '__main__':
    a = get_args()
    s = init_screen()
    g = GameController(a[0], a[1], a[2], s)
    try:
        curses.wrapper(g.play)
    except KeyboardInterrupt:
        exit_app(1, s)
    except curses.error:
        print("Please don't resize the window!")
        exit_app(1, s)
    except RuntimeError as e:
        print(str(e))
        exit_app(1, s)

    exit_app(0, s)