Ejemplo n.º 1
0
 def initialize(self, *args):
     self.human_players = args[0]
     self.game = Game(self.human_players)
     self.piece_repository = PieceRepository(settings.BOARD_RECT)
     self.board = Board(self.game, self.piece_repository, settings.BOARD_RECT)
     self.inventory = Inventory(self.game, self.piece_repository, settings.INVENTORY_RECT)
     self.initialized = True
Ejemplo n.º 2
0
def main():
    initialize_database()

    game = Game()

    while game.running:
        game.curr_menu.display_menu()
        game.run()
Ejemplo n.º 3
0
 def _handle_events_in_menu(self, event):
     if event.type == pygame.MOUSEBUTTONDOWN:
         if event.button == 1:
             if event.pos[0] > 273 and event.pos[0] < 383 and event.pos[
                     1] > 106 and event.pos[1] < 122:
                 self.view = "game"
                 self.game = Game()
             elif event.pos[0] > 270 and event.pos[0] < 325 and event.pos[
                     1] > 155 and event.pos[1] < 173:
                 self.view = "stats"
Ejemplo n.º 4
0
 def test_exceptions():
     # Too few mines
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 0))
     self.assertRaises(InvalidGame, lambda: Game(10, 10, -5))
     # Too many mines
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 100))
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 150))
     # Init mine outside range
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 50, (-5, 5)))
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 50, (5, -5)))
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 50, (5, 15)))
     self.assertRaises(InvalidGame, lambda: Game(10, 10, 50, (15, 5)))
Ejemplo n.º 5
0
 def test_open_cell_and_3bvs(self):
     game = Game(5, 5, 1)
     game.mine_map = np.array([
         [1, 1, 0, 0, 1],
         [0, 0, 0, 1, 0],
         [0, 0, 0, 0, 0],
         [1, 0, 0, 0, 1],
         [0, 0, 0, 0, 0],
     ])
     game.fill_numbers()
     game.open_cell((4, 2))
     self.assertEqual(game.get_3bvs(), 10)
Ejemplo n.º 6
0
 def test_bfs_number_cell(self):
     game = Game(5, 5, 1)
     game.mine_map = np.array([
         [1, 1, 0, 0, 1],
         [0, 0, 0, 1, 0],
         [0, 0, 0, 0, 0],
         [1, 0, 0, 0, 1],
         [0, 0, 0, 0, 0],
     ])
     game.fill_numbers()
     expected = {(3, 2), (3, 3), (3, 1), (2, 1), (2, 3), (4, 3), (2, 2),
                 (4, 2), (4, 1)}
     actual1 = game.bfs((4, 2))
     actual2 = game.bfs((3, 2))
     self.assertEqual(actual1, actual2)
     self.assertEqual(actual1, expected)
Ejemplo n.º 7
0
def game_start(top):
    global game, name_label, window
    window = top
    for widget in top.winfo_children():
        widget.destroy()

    game = Game(["AHP", "PKMS"])

    pieces = list(game.get_usable_piece_codes())

    piece_buttons = []

    for i in range(len(pieces)):
        piece = pieces[i]
        piece_button = Button(
            top,
            text=piece,
            command=lambda i=i: set_piece(pieces[i], piece_buttons[i]))
        piece_buttons += [piece_button]
        piece_button.grid(row=0, column=i)

    grid = game.cells
    grid_buttons = []

    for i in range(4):
        button_row = []
        for j in range(4):
            cell = grid[i][j]
            cell_text = '‌ ‌ ‌ ‌‌‌‌'
            if cell is not None:
                cell_text = cell.code
            grid_button = Button(
                top,
                text=cell_text,
                command=lambda i=i, j=j: put_piece(i, j, grid_buttons[i][j]))
            grid_button.grid(row=i + 3, column=j + 6)
            button_row += [grid_button]
        grid_buttons += [button_row]
    name = game.current_name()
    name_label = Label(top, text=name)
    name_label.grid(row=1, column=5)
Ejemplo n.º 8
0
 def setUp(self):
     self.game = Game()
     self.game_with_full_board = Game(225, 15)
     self.game_with_empty_board = Game(0, 15)
Ejemplo n.º 9
0
from datetime import datetime

import numpy as np

from logic.engine.satsolver import SatSolverEngine
from logic.game import Game
from logic.player import Player

# logging.basicConfig(level=logging.DEBUG)
np.set_printoptions(linewidth=160)

count = 0
with open("foo.csv", 'w') as fw:
    while True:
        count += 1
        game = Game(24, 30, 217, (0, 0))
        solver = SatSolverEngine()
        player = Player(game, solver)
        start = datetime.now()
        play = player.play()
        if play == 1:
            print("Done in {} tries".format(count))
            count = 0
        elapsed = (datetime.now() - start).total_seconds()
        print("Clear {}% in {}".format(100 * play, elapsed))
        fw.write("{},{}\n".format(play, elapsed))
Ejemplo n.º 10
0
def start_server():
    game = Game()
    threading._start_new_thread(start_listener, (game,))
Ejemplo n.º 11
0
 def test_init_cell():
     for i in range(3):
         for j in range(6):
             for _ in range(1, 18):
                 game = Game(3, 6, _, (i, j))
                 self.assertEqual(game.mine_map[i, j], 0)
Ejemplo n.º 12
0
 def test_no_init_cell():
     for i in range(1, 16):
         game = Game(3, 6, i)
         self.assertEqual(game.mine_map.sum(), i)
Ejemplo n.º 13
0
 def setUp(self):
     self.game = Game()
Ejemplo n.º 14
0
'''

import sys
from random import shuffle
from numpy import mean

from logic.game import Game
from utils.constants import Modes

mode = sys.argv[1]
if mode == Modes.PLAY:
    cardRange = int(sys.argv[2])
    numLives = int(sys.argv[3])
    powerTries = int(sys.argv[4])
    names = sys.argv[5:]
    game = Game(names, cardRange, numLives, powerTries)
    game.playGame()
elif mode == Modes.TRIAL:
    numTrials = int(sys.argv[2])
    writeStep = int(sys.argv[3])
    writeFile = sys.argv[4]
    cardRange = int(sys.argv[5])
    numLives = int(sys.argv[6])
    powerTries = int(sys.argv[7])
    names = sys.argv[8:]
    wins = {name: 0 for name in names}
    finishes = {name: [] for name in names}
    for i in range(numTrials):
        if i != 0 and i % writeStep == 0:
            with open("count.txt", "a") as f:
                f.write(
Ejemplo n.º 15
0
import os

# tylko, jesli skrypt zostal uruchomiony
if __name__ == '__main__':

    import os
    import sys
    from path import root_path

    from logic.game import Game

    game = Game()
    game.run()

Ejemplo n.º 16
0
FPS = 80
pygame.init()
screen = pygame.display.set_mode((W, H))

mi = MapInitializer("First demo map")
mi.chunk = (random.randint(0, 1000), random.randint(0, 1000))
wm, hm = 32, 16
mi.world_size = (wm, hm)
mi.set_terrain_type(terrain_medium, colorscale_normal)
mi.max_number_of_roads = random.randint(0, 6)
mi.max_number_of_rivers = random.randint(0, 6)
mi.zoom_cell_sizes = [32, 16]
mi.seed_static_objects = random.randint(0, 1000)
me = mi.configure_map_editor(FPS)  #me = "Map Editor"
img = me.get_hmap_img((wm * 10, hm * 10))
game = Game(me)

#<fast> : quality a bit lower if true, loading time a bit faster.
#<use_beach_tiler>: quality much better if true, loading much slower.
#<load_tilers> : Very slow but needed if you don't have Numpy but still want HQ.
game.build_map(mi, fast=False, use_beach_tiler=True, load_tilers=False)
me.set_zoom(level=0)

##game.set_fire((3,7))
##game.add_smoke("large",(4,4))

clock = pygame.time.Clock()
done = False
while not done:
    clock.tick(FPS)
    screen.fill((0, 0, 0))
Ejemplo n.º 17
0
from logic.ai import AI
from logic.ai_v2 import AIV2
from logic.game_essentials import LINES
from logic.ai_v2 import CPU_NAME

boardSize = 4
# bestParams = [1, 4, 20, 10**10]
# bestUserParams = [1, 4, 20, 10**10]

bestParams = [10, 31, 80, 10**10]
bestUserParams = [10, 31, 80, 10**10]

user = User()
cpu = AI(boardSize, CPU_NAME, user.getName(), bestParams, bestUserParams,
         LINES)
game = Game(user, cpu)
game.play()

# Playing the machines against each other
# while True:
# #   bar = random.randint(100, 1000000)
#   champ = AI(boardSize, 'Champ', 'Challenger', bestParams, bestUserParams, LINES)

#   challengerParams = []
#   lastNum = 1
#   first_param = random.randint(1, 10)
#   second_param = random.randint(first_param, 100)
#   third_param = random.randint(second_param, 1000)

#   challengerUserParams = [first_param, second_param, third_param, 10 ** 10]
# #   print(challengerUserParams)