def test_move_bar_not_empty(self): b = board.Board() b._x_points[5] -= 1 b._x_bar += 1 state = b.state() self.assertFalse(b.move(5, 2)) self.assertEqual(state, b.state())
def test_move_from_bar_ok(self): b = board.Board() b._x_points[5] -= 1 b._x_bar += 1 self.assertTrue(b.move("bar", 2)) self.assertEqual(0, b.x_bar()) self.assertEqual(1, b.x_points()[1])
def update_game_state(self): if self.game_state['winner'] != board.EMPTY: return step = self.game_state['gameStep'] player = self.game_state['players'][step % 2] color = player.color column = player.move(self.game_board) if column == -1: return new_state = self.game_board.move(column, color) # replace = { # board.EMPTY: '-', # board.RED: 'r', # board.YELLOW: 'y', # } # print new_state.pretty_log(replace) self.game_board = board.Board(state=new_state) win, coordinates = terminals.winner(self.game_board, self.game_state['expectedInLine'], return_coordinates=True) self.__draw_board() self.game_canvas.update() if win != board.EMPTY: self.moves_list.insert(END, "{} played on column {} and won".format(board.COLOR_NAMES[win], column + 1)) self.game_state['winner'] = win self.game_state['winCoordinates'] = coordinates self.__draw_board() return else: self.moves_list.insert(END, "{} played on column {}".format(board.COLOR_NAMES[color], column + 1)) self.moves_list.see("end") # self.moves_list.select_set(self.moves_list.size() - 1, self.moves_list.size() - 1) self.game_state['gameStep'] += 1 self.update_game_state()
def test_move_from_bar_blocked(self): b = board.Board() b._x_points[5] -= 1 b._x_bar += 1 state = b.state() self.assertFalse(b.move("bar", 1)) self.assertEqual(state, b.state())
def go_on_click(self): self.game_board = board.Board(int(self.columns_spinner_var.get()), int(self.rows_spinner_var.get())) expected_in_line = int(self.line_length_spinner.get()) minimax_depth = int(self.checked_depth_spinner.get()) self.moves_list.delete(0, END) if self.playing_for.get() == "Red": players_list = [ players.UIPlayer(board.RED, self.get_active_column), players.MiniMaxPlayer(board.YELLOW, terminals.combined_terminal, minimax_depth, expected_in_line), ] else: players_list = [ players.MiniMaxPlayer(board.RED, terminals.combined_terminal, minimax_depth, expected_in_line), players.UIPlayer(board.YELLOW, self.get_active_column), ] self.game_state = { 'gameStep': 0, 'players': players_list, 'winner': board.EMPTY, 'expectedInLine': expected_in_line, } width = self.game_canvas.winfo_width() height = self.game_canvas.winfo_height() # print "winfo_width = {}, winfo_height = {}".format(width, height) self.__calc_geometry(width, height, self.game_board.state.width, self.game_board.state.height) self.__draw_board() self.update_game_state()
def main(): """Main program.""" # ask human color game_board = board.Board() human_color = "white" computer_color = "black" human = player.Player("human", human_color) computer = player.Player("computer", computer_color) winner = False while not winner: draw_game(human, computer, game_board) move = raw_input("Please input your move: ") game_board.set_element(move, "HOR")
def createGame(request): global gameBoard if request.method == 'POST': # gets request and turns it into json to get it's values body_unicode = request.body.decode('utf-8') body = json.loads(body_unicode) rows = body['rows'] columns = body['columns'] num_of_bombs = body['num_of_bombs'] gameBoard = board.Board(int(rows), int(columns), int(num_of_bombs)) gameBoard.createBoard() return HttpResponse("game reset")
def test_encode_state_initial_state_x_turn(self): b = board.Board() state = b.encode_state(0) expected = np.array([ 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.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.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, 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.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, 0.0, 0.0, 0.0, 0.0, 1.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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.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, 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.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, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]) self.assertTrue((expected == state).all())
def test_move_out_of_bounds(self): b = board.Board() state = b.state() self.assertFalse(b.move(23, 2)) self.assertEqual(state, b.state())
def test_move_to_occupied_point(self): b = board.Board() state = b.state() self.assertFalse(b.move(7, 4)) self.assertEqual(state, b.state())
def test_hit(self): b = board.Board() b._o_points[7] = 1 self.assertTrue(b.move(12, 4)) self.assertEqual(0, b.o_points()[7]) self.assertEqual(1, b.o_bar())
def test_move_ok(self): b = board.Board() self.assertTrue(b.move(5, 2)) self.assertEqual(4, b.x_points()[5]) self.assertEqual(4, b.x_points()[7])
import pyglet from pyglet import shapes from game import board, controller, load, pawn, resources pyglet.options['debug_gl'] = False # something to do is smaller is way to big right now game_window = pyglet.window.Window(800, 700, resizable=True) main_batch = pyglet.graphics.Batch() # View board_view = board.Board(main_batch) # Controller board_control = controller.Controller(board_view, main_batch) board_control.draw_pawns() board_control.draw_rooks() board_control.draw_bishops() board_control.draw_queens() board_control.draw_kings() board_control.draw_knigths() # Lets assume that the player selected white for now # black_paws = load.paws("black", 225,925, 100, main_batch) game_window.push_handlers(board_control) @game_window.event
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts import render from rest_framework import viewsets from .serializers import BoardSerializer from django.http import HttpResponse, HttpRequest from .models import Board from game import board import json # Create your views here. gameBoard = board.Board(9, 9, 10) gameOver = False class BoardView(viewsets.ModelViewSet): serializer_class = BoardSerializer # all boards queryset = Board.objects.all() # gameBoard = board.Board(9, 9, 10) global gameBoard gameBoard.createBoard() # if request.method == 'POST': # create a new game def createGame(request): global gameBoard
def setUp(self) -> None: self.test_board = board.Board(self.test_board_str)
def test_move_point_empty(self): b = board.Board() state = b.state() self.assertFalse(b.move(0, 3)) self.assertEqual(state, b.state())
def test_move_step_too_small(self): b = board.Board() state = b.state() self.assertFalse(b.move(5, 0)) self.assertEqual(state, b.state())
def test_permitted_moves_one_step(self): b = board.Board() self.assertEqual([(5, 1), (7, 1), (12, 1), (23, 1)], b.permitted_moves([1, 1]))
def setUp(self) -> None: self.test_board = board.Board(self.input_board) self.strategy = AIStrategy()
def test_permitted_moves_blocked(self): b = board.Board() self.assertEqual([(5, 4), (7, 6)], b.permitted_moves([4, 6]))