예제 #1
0
    def __init__(self, window_dim):
        self.app = QtWidgets.QApplication(sys.argv)
        super(App, self).__init__()

        self.setWindowTitle("Game of Life")
        width, height = window_dim
        self.resize_window(width, height)
        self.timer = self.setup_timer()

        # this will keep track of whether the
        #  rendering has begun, added because
        #  the first frame is skipped and not
        #  rendered for some reason...see inside
        #  draw_rectangles method below*
        self.drawn = None

        board_width, board_height = (50, 50)
        self.board = main.Board(board_width, board_height,
                                ["grenade", "pulsar", "beacon", "arrow"],
                                [(1, 1), (5, 5), (10, 10), (40, 15)])
        #self.board = main.Board(board_width, board_height,
        #                        ["arrow", "pulsar"],
        #                        [(2,2),(4,4)])
        self.pixel_width, self.pixel_height = (width / board_width,
                                               height / board_height)

        self.show()
예제 #2
0
def server_connect():
    sock = socket.socket()
    sock.bind(('localhost', 9090))
    sock.listen(1)
    conn, addr = sock.accept()
    print("LOG: connected:", addr)
    board = main.Board()
예제 #3
0
 def __init__(self, username, password, opponent):
     self.cur_board = main.Board()
     self.player = None  #is player 0 or 1
     self.connected = 0
     self.username = username
     self.password = password
     self.opponent = opponent
     self.port = 4705
     self.buf = 1024
     self.ip = socket.gethostbyname('artemis.engr.uconn.edu')
     self.socket = socket.socket()
     self.socket.connect((self.ip, self.port))
     print("Player connected to server")
예제 #4
0
    def test_03(self):
        b = main.Board(5, 5)
        r = b.get_random_board()
        r_height = len(r)
        e_height = 5
        self.assertEqual(r_height, e_height)

        all_cells_valid = True
        for row in r:
            for col in row:
                if col not in [0, 1]:
                    all_cells_valid = False
                    break
        self.assertTrue(all_cells_valid, ("cell %s is not valid" % col))
예제 #5
0
import donk
import firecoin
import purse
import pygame
import main
from pygame.locals import *
play = main.Board()


class Test_donkey():
    def test_donk(self):
        self.dragon = donk.Donkey('demon5.png', 40, 60, 60, 525)
        self.dragon.rect.x = self.dragon.rect.x + 10
        self.lim = self.dragon.limit()
        assert self.dragon.rect.x >= self.lim[0]
        assert self.dragon.rect.x <= self.lim[1]


class Test_player():
    def test_limit(self):
        self.god = purse.Player()
        self.lim = self.god.limit()
        for i in range(5):
            assert self.god.rect.x >= self.lim[0]
            assert self.god.rect.x <= self.lim[1]
            self.god.rect.x = self.god.rect.x - 10
            self.god.check()
        assert self.god.rect.x >= self.lim[0]
        assert self.god.rect.x <= self.lim[1]

        self.god.rect.x = 585
예제 #6
0
 def test_08(self):
     b = main.Board(3, 3)
     b.seed = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
     r = b.get_next_state()
     e = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
     self.assertEqual(r, e)
예제 #7
0
 def test_02(self):
     b = main.Board(0, 0)
     r = b.get_dead_board()
     e = []
     self.assertEqual(r, e)
예제 #8
0
 def test_01(self):
     board = main.Board(5, 5)
     result = board.get_dead_board()
     expected = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
     self.assertEqual(result, expected)
예제 #9
0
    lose = 0
    draw = 0

    # 対戦用の初期設定
    FIRST, SECOND = '◯', '×'
    player_radom = main.Player_random('×')
    player_learned = main.Player_using_table(turn='◯')

    for episode in range(1, GAMES):
        # episodeの偶奇で先攻後攻を変えている
        if episode % 2 == 0:
            which_turn = FIRST
        else:
            which_turn = SECOND

        board = main.Board()
        is_judge_draw = True
        while board.can_put():
            if which_turn == FIRST:
                # player_1.random_put(board.can_put(), board)
                action, row_index = player_learned.q_table_put(
                    board.can_put(), board)
                if board.judge(which_turn) is True:
                    # board.print()
                    win += 1
                    is_judge_draw = False
                    break
            else:
                player_radom.random_put(board.can_put(), board)
                if board.judge(which_turn) is True:
                    # board.print()