def _draw_house(): btn = c.BUTTON_POSITION + _DRAW_OFFSET hog = btn - pymunk.Vec2d(0, utils.dist(feet=21)) pygame.draw.circle(screen, (164, 211, 255), btn, utils.dist(feet=6)) pygame.draw.circle(screen, (255, 255, 255), btn, utils.dist(feet=4)) pygame.draw.circle(screen, (255, 164, 211), btn, utils.dist(feet=2)) pygame.draw.circle(screen, (255, 255, 255), btn, utils.dist(feet=0.5)) pygame.draw.line(screen, 'black', [(btn.x), 0], [btn.x, 1000]) # Centerline pygame.draw.line(screen, 'black', [(btn.x) - 100, btn.y], [(btn.x + 100), btn.y]) # tee line pygame.draw.line(screen, 'blue', [(hog.x - 100), hog.y], [(hog.x + 100), hog.y]) # hog line
def test_it_curls_right(): curl = game.CurlingGame() board = curl.getInitBoard() curl.getNextState(board, 1, utils.getAction(1, '5', 1)) stone = curl.sim.getStones()[0] right_house = utils.dist(feet=5) assert stone.body.position.x > right_house # positive handle, positive broom, should cross over the center
def SKIP_test_simulation_getBoard_right_edge(): sim = game.CurlingGame().sim board = sim.getBoard() board[-1][0] = c.EMPTY button_x, button_y = curling.constants.BUTTON_POSITION button_x -= utils.dist(inches=10) # NOTE - shifting to the left board_x, board_y = utils.realToBoard(button_x, button_y) board[board_x][board_y] = c.P1 sim.setupBoard(board) stones = sim.getStones() assert len(stones) == 1 stone_x, stone_y = stones[0].body.position assert (button_x, button_y) == (stone_x, stone_y) recalculated_board = sim.getBoard() expected = np.argwhere(board == c.P1) actual = np.argwhere(recalculated_board == c.P1) np.testing.assert_array_equal(expected, actual)
# y values # 0,1 - has this stone been thrown yet # 0,1 - is this stone "valid" (1) or "out of play" (0) (touched a wall) # distance to pin # 0,1 - is scoring # [ # [0] * 16, # [0] * 16, # [0] * 16, # [1] * 16 # [0] * 16, # [0] * 16, # ] _HOUSE_RAIDUS = utils.dist(feet=6, inches=c.STONE_RADIUS_IN) def update_distance_and_score(board: np.array): for stone in board.T: xy = pymunk.Vec2d(stone[c.BOARD_X], stone[c.BOARD_Y]) stone[c.BOARD_DISTANCE] = utils.euclid(xy, c.BUTTON_POSITION) shot_stones = np.argsort(board[c.BOARD_DISTANCE]) if shot_stones[0] < 8: team_range = range(0, 8) else: team_range = range(8, 16) board[c.BOARD_SCORING].fill(c.NOT_SCORING)
from unittest import mock import numpy as np import curling.constants import log_handler from curling import board as board_utils from curling import constants as c from curling import game from curling import utils inch = utils.dist(inches=1) log_handler.flush_on_error() class UnitTestException(Exception): """For testing expected exceptions.""" def test_board_is_2d(): curl = game.CurlingGame() board = curl.getInitBoard() height, width = board.shape assert width == 16 assert height == 6 def test_CanonicalBoard_unchanged(): curl = game.CurlingGame() original = curl.getInitBoard()