def main(): pygame.init() pygame.display.set_caption("Mines!") screen = pygame.display.set_mode(tuple(settings.SCREEN_SIZE)) running = True ended = False board = logic.Board(settings.MINE_COUNT) draw_board(board, screen) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: if ended: board = logic.Board(settings.MINE_COUNT) ended = False else: left_click(board, vec(event.pos)) elif event.button == 3: right_click(board, vec(event.pos)) draw_board(board, screen) status = board.get_status() if status != 'Ok': ended = True draw_text(status, screen)
def test_GetValueFromBoard(self): """ in: value from GetValueFromBoard, self calulate value do: combare if the Method GetValueFromBoard with a the value from that is on the board itself out: if test run good or with an error """ testboard = np.array([[2, 0], [0, 0]], dtype=int) test = logic.Board(2, 2, 0, testboard) self.assertEqual(2, test.getValueFromBoard(0, 0))
def test_is_in_mill(self): board = logic.Board() walter = logic.Player('Walter', 'white') for i in range(3): board.move_piece(walter, new_field=logic.Field('outer', i, walter)) for field in board.get_all_fields(walter)['outer']: self.assertTrue(board.is_in_mill(field)) field = logic.Field('mid', 1, walter) self.assertFalse(board.is_in_mill(field))
def test_getOpenFiledsAmount(self): """ in: the output of getOpenFieldsAmount with the given field do: Check if the output and the self calculated value are the same out: if test run good or with an error """ testboard = np.array([[1, 11, 0, 1, 1], [10, 2, 1, 1, 10], [2, 11, 1, 11, 1], [1, 2, 2, 1, 0], [0, 1, 11, 1, 0]], dtype=int) getOpenFiledsAmountTestBoard = logic.Board(5, 5, 3, testboard) self.assertEqual(getOpenFiledsAmountTestBoard.getClickedFieldsAmount(), 4)
def test_get_allowed_fields(self): board = logic.Board() walter = logic.Player('Walter', 'white') peter = logic.Player('Peter', 'black') for square, i in [('outer', 0), ('mid', 1), ('outer', 2)]: board.move_piece(walter, new_field=logic.Field(square, i, walter)) board.move_piece(peter, new_field=logic.Field('outer', 1, peter)) allowed = board.get_allowed_fields(logic.Field('mid', 1, walter)) self.assertIn(logic.Field('mid', 0), allowed['mid']) self.assertIn(logic.Field('mid', 2), allowed['mid']) self.assertNotIn(logic.Field('outer', 1), allowed['outer'])
def __init__(self): self.board = graphics.Board() self.board_logic = logic.Board() self.cells = self.create_cells(CELL) self.player_score = graphics.Text('P1 : 0', (WIDTH * 4 // 5, TOP * 1 // 3)) self.cpu_score = graphics.Text('CPU : 0', (WIDTH * 4 // 5, TOP * 2 // 3)) self.end_message = graphics.Text('', (WIDTH * 2 // 5, TOP // 2)) self.player_play = False self.check = False self.reset = False self.timer = 0 self.timer2 = 0
def test_GetAllOtherOpenFieldsNotReturnNone(self): """ in: the output off all fileds with method GetAllOtherOpenFields do: Check off if None back, this is because off this is the case if the GetAllOpenFields do not come to an return out: if test run good or with an error """ test2 = logic.Board(10, 10, 1, None) test2.createWarnFields() # because sometimes they give None pack for i in [0, 10]: for j in [0, 10]: listOfOpentest2 = test2.getAllOtherOpenFields(i, j, []) self.assertIsNotNone(listOfOpentest2)
def test_CreateWarnField(self): """ in: self calculate board how have to look like the board after createwarnfileds, the board after the method CreateWarnfileds do: Prepare for test and combare the inputs out: if test run good or with an error """ testboard = np.array([[10, 0], [0, 0]], dtype=int) test = logic.Board(2, 2, 1, testboard) test.createWarnFields() HowTheBoardLooksLike = np.array([[10, 1], [1, 1]], dtype=int) self.assertTrue(np.array_equal(test.getBoard(), HowTheBoardLooksLike))
def test_GetAllOtherOpenFields(self): ''' use these special testcase because off, it destroy the programm by the first implementation from GetAllOtherFields in: the fields in on array off tubles that should, be open from GetAllOtherOpenFileds, the fields in on array off tubles that open from GetAllOtherOpenFileds, do: prepare the test and compare the inputs out: if test run good or with an error ''' testboard = np.array([[1, 1, 0, 1, 1], [10, 2, 1, 1, 10], [2, 10, 1, 1, 1], [1, 2, 2, 1, 0], [0, 1, 10, 1, 0]], dtype=int) test = logic.Board(5, 5, 3, testboard) listOfOpen = test.getAllOtherOpenFields(2, 0, []) fieldsHaveToBeOpen = [(1, 0), (2, 0), (3, 0), (1, 1), (2, 1), (3, 1)] self.assertTrue(not sum([i not in listOfOpen for i in fieldsHaveToBeOpen]))
import tornado.ioloop import tornado.web import tornado.template import tornado.websocket import time import tornado.ioloop import json import logic #import asyncio.AbstractEventLoop cl = [] b = logic.Board() # b.play_word( "touzy", 0, 0, logic.RIGHT, "comp" ) #comp # b.play_word( "oy", 0, 1, logic.RIGHT, "Josh" ) #Joshua # b.play_word( "zenith", 3, 0, logic.DOWN, "Jessica" ) #Jessica # b.play_word( "hit", 3, 5, logic.RIGHT, "Hannah" ) #Hannah # b.play_word( "diether", 0, 4, logic.RIGHT, "comp" )#comp class MainHandler(tornado.web.RequestHandler): def get(self): self.render("index.html") #pulling from https://github.com/hiroakis/tornado-websocket-example/blob/master/app.py class SocketHandler(tornado.websocket.WebSocketHandler): def check_origin(self, origin): return True # #computed = await AbstractEventLoop.run_in_executor(None, long_compute, None) # g = self.long_compute_gen( 10 )
def __init__(self): self.board = logic.Board() self.history = []