def __init__(self, players, rounds): self.info_dic = {"bankrupt_turn": {}} self.players = players self.board = Board() self.chancePile = ChancePile() self.communityPile = CommunityPile() self.rounds = rounds self.bankrupt_count = 0 self.cur_round = 0
def __init__(self): pygame.init() self.window = pygame.display.set_mode(RESOLUTION) pygame.display.set_caption('ТНН шашки') self.clock = pygame.time.Clock() self.board = Board() self.checkers = GroupChecker() self.checkers.reset_pos_checkers() self.step = (255, 255, 255) self.widgets = [ Widget(x=512, y=0, width=128, height=96, text='Reset', font_size=30, background_color=(255, 175, 88), background_color_cover=(255, 195, 131), background_color_click=(255, 132, 0), font_color=(168, 88, 2), onclick=self.reset), Widget(x=512, y=512 - 96, width=128, height=96, text='Exit', font_size=30, background_color=(255, 175, 88), background_color_cover=(255, 195, 131), background_color_click=(255, 132, 0), font_color=(168, 88, 2), onclick=self.exit), ] self.scores = [ Widget(x=512, width=128, height=160, y=96, text='0', font_size=50, background_color=(238, 191, 140), font_color=(168, 88, 2)), Widget(x=512, width=128, height=160, y=256, text='0', font_size=50, background_color=(238, 191, 140), font_color=(168, 88, 2)), ] self.score_black = 0 self.score_white = 0
def move(): global PREV_DATA_BY_GAME_ID print("\nPINGED\n ********************") data = request.get_json(force=True) # dict snake_dict = create_snake_dict(data['snakes']) board = Board(data['height'], data['width'], snake_dict, data['food']['data']) prev_food_list = PREV_DATA_BY_GAME_ID[data['id']]['prev_food_list'] # insert info about which snakes ate last turn into data object if prev_food_list is not None: data['ate_last_turn'] = find_snakes_that_just_ate(data, prev_food_list, board) PREV_DATA_BY_GAME_ID[data['id']]['prev_food_list'] = convert_to_coords_list(data['food']['data']) move = pick_move(data, board, snake_dict) response = { 'move': move, 'taunt': 'Squaack' } return json.dumps(response)
def move(): global PREV_DATA_BY_GAME_ID print("\nPINGED\n ********************") start = time() data = request.get_json(force=True) # dict snake_dict = create_snake_dict(data['snakes']) board = Board(data['height'], data['width'], snake_dict, data['food']['data'], data['you']['id']) try: prev_food_list = PREV_DATA_BY_GAME_ID[data['id']]['prev_food_list'] except KeyError: # bit of a hack, but lets us restart the game server and resume the same game # without issues. Also good if we ever crash mid game print("Failed to retrieve prev turn data") prev_food_list = None # insert info about which snakes ate last turn into data object if prev_food_list is not None: data['ate_last_turn'] = find_snakes_that_just_ate(data, prev_food_list, board) try: PREV_DATA_BY_GAME_ID[data['id']]['prev_food_list'] = convert_to_coords_list(data['food']['data']) except KeyError: print("Failed to update prev food list for next turn") pass end = time() print("Took", (end - start), "to build the board and setup game data") move_alone = time() move = pick_move(data, board, snake_dict) print("Computing the move took", (move_alone - start), "time") end = time() print("Took", (end - start), "to compute move", move) response = { 'move': move, 'taunt': "ITS NOT A BUBBLE. WE WON'T CRASH" } return json.dumps(response)
""" Basic pygame interface for minesweeper - Written by SC 15/07/19 - edited by jmc 25/07/19 """ import pygame from objects import Board # initialise board size and number of bombs board = Board(10, 25) bombs = board.bombs() size = board.size() # for now we just stick to 10 pygame.init() # pygame text size fontsize = 3*size font = pygame.font.Font('freesansbold.ttf', fontsize) # define colours green = (0, 135, 56) blue = (0, 0, 255) red = (128, 13, 0) turquoise = 12, 179, 151 black = (0, 0, 0) white = (255, 255, 255) grey = (140, 140, 140) lightgrey = (207, 207, 207)
from random import choice from tkinter import Tk, TclError from constraints import Direction from objects import Snake, Board from welcome_window import create_preference_window try: speed, length, height = create_preference_window() tk = Tk() tk.title("snake") tk.resizable(False, False) board = Board(tk, length, height, bg='white') board.pack() snake = Snake(board, board.find_center_field()) egg = None def finish_step(): tk.quit() snake.move() while True: tk.after(speed, finish_step) if egg and snake.is_eat(egg): snake.is_growing = True board.delete(egg)
def game(): #make player instances, player1 = Player(Board(), Board(True), 'Player1') CPU = Player(Board(), Board(True), 'CPU') available_ships = ['sub', 'aircraft', 'patrol', 'patrol'] print 'Welcome to Battleship!' print 'To place your battleship enter a phrase such as "Place sub horizontal at A2" or "Place aircraft, vert, at (C,4)"' print '' print '' #Player 1 places his ships here while available_ships: player1.defense_board.print_board() print '{}, your board is pictured above for reference.'.format(player1.name) print 'You have the following ships left for placement: {}'.format(available_ships) defense_request = raw_input('Type your placement phrase here: ') try: parsed_request = parse(defense_request) except ValueError as e: print e continue #this should probably be an exception if parsed_request[0] not in available_ships: print "You've already placed your {}, as a reminder, you have the following ships left for placement: {}".format(parsed_request[0], available_ships) continue try: player1.defense_board.place_boat(*parsed_request) available_ships.remove(parsed_request[0]) except ValueError as e: print e #AI places his ships here, core logic executed in AI library. ai.boat_placement(CPU.defense_board) #Flip a coin to determine who goes first. print 'Battleships placed for {} and computer.'.format(player1.name) #using turn to alternate turns turn = True players = (player1, CPU) while not any([player1.has_win, CPU.has_win]): if turn: player = players[0] print 'Here\'s your current board used for tracking your attacks:' print '' player.attack_board.print_board() coordinate = raw_input('Player {} Enter your coordinate: '.format(player.name)) try: parsed_coord = coordinate_parse(coordinate) if players[1].defense_board[parsed_coord][0]: print 'Hit!' player.attack_board[parsed_coord][0] = 'x' else: print 'Miss!' player except ValueError as e: print e continue else: player = players[1] turn = not turn
def drawCell(pos_x,pos_y): blockSize = Board.get_BlockSize(10) for x in range(width//blockSize): for y in range(height//blockSize): rect = pygame.Rect(x*blockSize, y*blockSize, blockSize, blockSize) if x==pos_x-1 and y==pos_y-1: pygame.draw.rect(screen, kolor.convert('red'), rect, 0) if x*blockSize >=width or y*blockSize >=height: break board=create_board(10,10) board=create_cell(3,4) Board=Board(width,height) screen.fill(kolor.convert('white')) Board.drawGrid(10) counter=0 while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run =False drawCell(5,5) sleep(2) drawCell(1,1) text("Klaudiusz Hynek",32,kolor.full_random_color()) pygame.display.update()