コード例 #1
0
ファイル: game.py プロジェクト: drcjar/quantumTTT
def play():
    b = board.init()
    for round in range(1,9):
        b = turn(b)
        board.draw(b)
        c = state.find_cycle(b)
        if c:
            pass
        if state.won(b):
            break
コード例 #2
0
ファイル: game.py プロジェクト: kynan/quantumTTT
def play():
    b = board.init()
    for r in range(9):
        b = turn(r, b)
        board.draw(b)
        c = state.find_cycle(b)
        if c:
            pos, symbol = prompt_resolve(r, c)
            b = state.collapse(b, pos, symbol)
        if state.won(b):
            print "Player %d won!" % playernum(r)
            break
コード例 #3
0
def setup():
    global firstRun
    if firstRun == False:
        resetBoard()
        return

    firstRun = False

    boardState = [[7, 7], [0, 0], [0, 0], [0, 0], [0, 0], 0, 0, 0, 0, 0, 0, 0,
                  0, [0, 0], [0, 0], [0, 0]]
    global whiteStartCount
    global blackStartCount
    global whiteEndCount
    global blackEndCount
    if globalvars.turtleMode:
        whiteStartCount = turtle.Turtle()
        blackStartCount = turtle.Turtle()
        whiteEndCount = turtle.Turtle()
        blackEndCount = turtle.Turtle()
        board.draw()

        #score turtles
        whiteStartCount.hideturtle()
        whiteStartCount.up()
        whiteStartCount.goto(0, 250)
        whiteStartCount.write("0", False, "center", ("Arial", 20, "normal"))

        blackStartCount.hideturtle()
        blackStartCount.up()
        blackStartCount.goto(0, -280)
        blackStartCount.write("0", False, "center", ("Arial", 20, "normal"))

        whiteEndCount.hideturtle()
        whiteEndCount.up()
        whiteEndCount.goto(200, 250)
        whiteEndCount.write("0", False, "center", ("Arial", 20, "normal"))

        blackEndCount.hideturtle()
        blackEndCount.up()
        blackEndCount.goto(200, -280)
        blackEndCount.write("0", False, "center", ("Arial", 20, "normal"))

    for i in range(7):
        if globalvars.turtleMode:
            setScore(blackStartCount, i + 1)
        BlackPiece()
        if globalvars.turtleMode:
            setScore(whiteStartCount, i + 1)
        WhitePiece()
コード例 #4
0
def _safe_local(id=None, snakes=None, food=None, height=None, width=None):
    head = snakes[id][0]
    g = board.draw(id=id, snakes=snakes, food=food, height=height, width=width)
    w, h = path.size(g)
    for (x, y) in path.neighbours(head, h, w):
        if g[y][x].type == board.TYPES.SNAKE:
            continue
        return [head, (x, y)]
    return None
コード例 #5
0
def _weights(id=None, snakes=None, food=None, height=None, width=None):
    g = board.draw(id=id, snakes=snakes, food=food, height=height, width=width)
    head = snakes[id][0]

    matrix = path.matrix(
        height=height,
        width=width,
        initial=head,
        cost_fn=_cost(g, snakes, id),
    )
    return matrix
コード例 #6
0
def test_move_around_snake():
    state = dict(
        id='1',
        snakes={
            '1': [(0, 2), (0, 1)],
            '2': [(1, 3), (0, 3)],
        },
        food=[(0, 9)],
        height=10,
        width=10,
        health=10,
        friendlies={
            '1': True,
            '2': False
        },
    )
    board.pretty_print(board.draw(**state))
    assert move(**state) == 'up'
    assert _ideal_path(**state)[:2] == [(0, 2), (0, 3)]
コード例 #7
0
def test_move():
    state = dict(
        id='1',
        snakes={
            '1': [(0, 2), (0, 1)],
            '2': [(4, 4), (4, 5)],
        },
        food=[(0, 3)],
        height=10,
        width=10,
        health=10,
        friendlies={
            '1': True,
            '2': False
        },
    )
    board.pretty_print(board.draw(**state))
    # Direction up because that's where the nearest food is.
    assert move(**state) == 'up'
    assert _ideal_path(**state) == [(0, 2), (0, 3)]
コード例 #8
0
ファイル: tetris.py プロジェクト: Benrflanders/Pytris
def on_draw():
    win.clear()
    board.draw()
コード例 #9
0
def redrawEverything(board, currentPlayer, players, gameOver, gameMenu):
    DISPLAYSURF.fill(BACKGROUND_COLOR)
    board.draw(DISPLAYSURF, ALPHASURF)
    currentPlayer.drawTray(DISPLAYSURF)
    drawScore(players, gameOver)
    gameMenu.redraw()
コード例 #10
0
            for win in gui.windows:
                if win.click(point):
                    inwindow = True
                elif win.ispointin(point):
                    inwindow = True
                    movingwindow = win
            if not inwindow and board.initialized:
                mousedown(e.button, point)
        elif e.type == pygame.MOUSEBUTTONUP:
            movingscreen = False
            movingwindow = None
        elif movingwindow and e.type == pygame.MOUSEMOTION:
            movingwindow.move(
                (float(e.rel[0]) / size[1], float(e.rel[1]) / size[1]))
        elif board.initialized and movingscreen and e.type == pygame.MOUSEMOTION:
            board.movemap(
                (-float(e.rel[0]) / size[1], -float(e.rel[1]) / size[1]))
    dt = (pygame.time.get_ticks() - lastframe) / 1000.0
    lastframe = pygame.time.get_ticks()
    for a in texture.animations:
        a.tick(dt)
    if board.initialized:
        board.advtime()
    screen.startframe()
    if board.initialized:
        board.draw()
    for win in gui.windows:
        win.draw()
    screen.endframe()
    pygame.time.wait(1)
コード例 #11
0
 def handle(self, params):
     print "Comando: %s"  % params["text"]
     board.move(params["text"])
     board.draw()
コード例 #12
0
ファイル: main.py プロジェクト: jorgeramirez/step
#!/usr/bin/env python

import gobject

import asr, board

class ResultListener(asr.Listener):
    def handle(self, params):
        print "Comando: %s"  % params["text"]
        board.move(params["text"])
        board.draw()



if __name__ == "__main__":
    recognizer = asr.Recognizer()
    board = board.Board()
    
    recognizer.add_result_listener(ResultListener())
    
    board.draw()
    
    gobject.threads_init()
    gobject.MainLoop().run()
コード例 #13
0
ファイル: scrabble.py プロジェクト: ScottHYoung/wordsmith
def redrawEverything(board, currentPlayer, players, gameOver, gameMenu):
	DISPLAYSURF.fill(BACKGROUND_COLOR)
	board.draw(DISPLAYSURF, ALPHASURF)
	currentPlayer.drawTray(DISPLAYSURF)	
	drawScore(players, gameOver)
	gameMenu.redraw()
コード例 #14
0
ファイル: main.py プロジェクト: jacob-dale/nea
def redraw():  # redraws both sets of pieces and the board
    board = Board()
    board.draw()
    white.draw()
    black.draw()
コード例 #15
0
ファイル: triad.py プロジェクト: TheSOB88/triad-game
def main():
    gameWindow = Rect(0, 0, 800, 704)
    clock = pygame.time.Clock()

    main_dir = os.path.split(os.path.abspath(__file__))[0]

    # Initialize pygame
    pygame.init()
    if pygame.mixer and not pygame.mixer.get_init():
        print('Warning, no sound')
        pygame.mixer = None
    pygame.display.set_caption('Tritris v0.1')

    # Set the display mode
    winstyle = 0  # |FULLSCREEN
    bestdepth = pygame.display.mode_ok(gameWindow.size, winstyle, 32)
    screen = pygame.display.set_mode(gameWindow.size, winstyle, bestdepth)

    boardSurface = pygame.Surface((BOARD_WIDTH * 48, BOARD_HEIGHT * 48),
                                  pygame.SRCALPHA)
    boardCorner = (24 * 16, 64)
    boardX, boardY = boardCorner
    board = Board(BOARD_WIDTH, BOARD_HEIGHT)

    if doDemo:
        #instantiate demo pieces
        demoPieces = [None] * 8
        for i in range(0, 8):
            demoPieces[i] = Piece(i + 1, (i % 4) * 2, 8 + int(i / 4) * 2,
                                  colors[i])
            board.addPiece(demoPieces[i])
            demoPieces[i].y -= 8
    else:
        #instantiate game stuff
        pieceType = 8
        currentPiece = None
        moveControls = set(('left', 'right', 'down'))
        moveTicks = 0
        moveDelay = 20
        gravityTicks = -1

    demoClockwise = True
    ticks = -1
    globalTicks = -1

    quitGame = False

    gameBG = pygame.Surface(gameWindow.size)
    if demoGrids:
        drawScreenGrid(gameBG, cGrid, gameWindow)
    draw.rect(gameBG, cGameBG,
              (boardCorner, (BOARD_WIDTH * 48, BOARD_HEIGHT * 48)))
    if demoGrids:
        drawBoardGrid(gameBG, cGameGrid, boardX, boardY)

    while not quitGame:
        globalTicks += 1

        controlsReturnVal = processControls()
        if controlsReturnVal == "quit":
            quitGame = True
            print('quittin\'')
        elif controlsReturnVal == "clock":
            demoClockwise = not demoClockwise

        screen.fill(Color(0, 0, 0))
        boardSurface.fill(Color(0, 0, 0, 0))

        if doDemo:
            ticks += 1
            if ticks == 30:
                for i in range(0, 8):
                    demoPieces[i].rotate(demoClockwise)
                ticks = 0

            board.draw(boardSurface)
            for i in range(0, 8):
                demoPieces[i].draw(boardSurface)
        #game logic
        else:
            #create new piece if none currently
            if not currentPiece:
                ##TODO: make the piece random

                pieceNewX = round(board.width / 2)
                pieceNewX -= 1 if pieceType > 4 else 0
                currentPiece = Piece(pieceType, pieceNewX, 0,
                                     colors[pieceType - 1])
                gravityTicks = 0

            #update timers
            if len(newControls) > 0:
                newDirections = newControls.intersection(moveControls)
                if len(newDirections) > 0:
                    moveTicks = -1
                    moveDelay = 20
                if 'rotateR' in newControls:
                    board.rotate(currentPiece, True)
                if 'rotateL' in newControls:
                    board.rotate(currentPiece, False)
            moveTicks += 1
            gravityTicks += 1

            currentPiece.oldX = currentPiece.x
            currentPiece.oldY = currentPiece.y

            #check for directional move
            if (controls['down'] or controls['left']
                    or controls['right']) and moveTicks == 0:
                moveTicks = moveDelay * -1
                moveDelay = 8
                #do move
                if controls['down']:
                    currentPiece.y += 1
                    gravityTicks = 0
                if controls['left']:
                    currentPiece.x -= 1
                if controls['right']:
                    currentPiece.x += 1

            #gravity
            if gravityTicks == 45:
                gravityTicks = 0
                ##pieceMoved = True

                currentPiece.y += 1

            doAddPiece = board.checkBoundaries(currentPiece)
            if doAddPiece:
                board.addPiece(currentPiece)
                pieceType = pieceType + 1 if pieceType < PIECE_TYPES else 1
                currentPiece = None
                board.draw(boardSurface)
            else:
                if currentPiece.oldX != currentPiece.x or currentPiece.oldY != currentPiece.y:
                    x, y = currentPiece.x, currentPiece.y
                    xDelta = (x - currentPiece.oldX) * .334
                    yDelta = (y - currentPiece.oldY) * .334
                    currentPiece.x = currentPiece.oldX + xDelta
                    currentPiece.y = currentPiece.oldY + yDelta
                    times = 0
                    while times < 3:
                        screen.blit(gameBG, (0, 0))
                        boardSurface.fill(Color(0, 0, 0, 0))
                        board.draw(boardSurface)
                        currentPiece.draw(boardSurface)
                        screen.blit(boardSurface, boardCorner)
                        pygame.display.update()
                        clock.tick(60)
                        currentPiece.x += xDelta
                        currentPiece.y += yDelta
                        times += 1

                currentPiece.x = round(currentPiece.x)
                currentPiece.y = round(currentPiece.y)

                board.draw(boardSurface)
                currentPiece.draw(boardSurface)

        screen.blit(gameBG, (0, 0))
        screen.blit(boardSurface, boardCorner)
        pygame.display.update()
        #cap the framerate
        clock.tick(60)

    pygame.quit()
コード例 #16
0
        elif (snake.dir == 4):
            move_cell = board.get_cell(snake.pos.x - 1, snake.pos.y)
            if move_cell:
                if not snake.move(move_cell):
                    done = True
            else:
                done = True

        if snake.pos.has_food:
            snake.pos.has_food = False
            snake.add_part()
            board.cells[randint(0, NUM_CELLS[0] - 1)][randint(
                0, NUM_CELLS[1] - 1)].has_food = True
            reward = 1000

        new_state = get_state()
        score += reward
        brain.store_transition(state, action, reward, new_state, done)
        brain.learn()
        state = new_state

        if done:
            reward = -100
            scores.append(score)

        DISPLAYSURF.fill(WHITE)
        #print(get_mouse_pos_index())
        board.draw(DISPLAYSURF)
        snake.draw(DISPLAYSURF)
        pygame.display.update()
コード例 #17
0
ファイル: main.py プロジェクト: Elijah-Code/Checkers
stop_game = False

# game loop
while not stop_game:
    # Event handling
    for event in pygame.event.get():  # User did something
        if event.type == pygame.QUIT:  # If user clicked close
            stop_game = True  # Flag that we are stop_game so we exit this loop

        if event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            click_handler(mouse_x, mouse_y)

    # First, clear the screen to black. Don't put other drawing commands
    # above this, or they will be erased with this command.
    screen.fill(BLACK)

    # draw the game board and marks:
    board.draw(screen)

    # --- Go ahead and update the screen with what we've drawn.
    pygame.display.flip()

    # --- Limit to 60 frames per second
    # clock.tick(60)

# Close the window and quit.
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
pygame.quit()
コード例 #18
0
ファイル: damas.py プロジェクト: enmanuelar/damas_project
							board.eat(coordinates_array, release_pos, next_coordinates, enemy_pos, current_enemy_array)
							current_player_array, current_enemy_array = board.change_player(current_turn, top_player_array, bottom_player_array)
							current_turn = board.change_turn(current_turn)

						else:
							current_player_array, current_enemy_array = board.change_player(current_turn, top_player_array, bottom_player_array)
							current_turn = board.change_turn(current_turn)

				check_selected = False
			else:
				check_selected = False


	#============DRAW=============
	window_surface.blit(background, (0,0))
	board.draw(window_surface)
	window_surface.blit(label, (540, 216))

	if game_over == False:
		if current_turn == [2, 4]:
			top_player.draw_current_turn(window_surface)
		else:
			bottom_player.draw_current_turn(window_surface)

	if len(current_player_array) > 0:
		for checker in bottom_player_array:
			checker.draw(window_surface)

		for checker in top_player_array:
			checker.draw(window_surface)
	else: