Beispiel #1
0
def on_incoming_data(data: str) -> str:
    global board

    try:
        action = get_player_action(data)
    except ValueError:
        return "{}"

    #Reset the game board
    if action == "reset":
        board.reset()
        return "{}"

    #Send the current board to the client
    elif action == "getstate":
        array = board.get_board()
        return json.JSONEncoder().encode({"moves": array})

    #Allow the player to move
    elif action == "move":

        try:
            move = get_player_move(data)
            return board.player_move(move)
        except ValueError:
            return "{}"
    else:
        return "{}"
Beispiel #2
0
def run_example():
    board.reset(True)
    board.add_solutions("3 1 9, 7 1 7, 8 1 3, 9 1 1, 2 2 3, 6 2 7, 4 3 3, 5 3 4, 7 3 8, 1 4 7, 8 4 5, 1 5 8, 2 5 9, 4 5 5, 6 5 6, 8 5 4, 9 5 7, 2 6 5, 9 6 6, 3 7 6, 5 7 5, 6 7 9, 4 8 2, 8 8 1, 1 9 5, 2 9 8, 3 9 2, 7 9 3")
    board.solution_pool.execute_all_init_triplets()
    print(str(board.get_amount_of_solved_cells()) + " cells have been solved.")
    print(str(board))
    print("Above is an example setting. Input 'solve' to solve the sudoku. Or input 'help' to show all commands.")
Beispiel #3
0
def new():
    # Reset the board to the standard chess starting position. Set White
    # on move. Leave force mode and set the engine to play Black.
    # Associate the engine's clock with Black and the opponent's clock
    # with White. Reset clocks and time controls to the start of a new
    # game. Stop clocks. Do not ponder on this move, even if pondering is
    # on. Remove any search depth limit previously set by the sd command.
    global engineColor
    stopClocks()
    board.reset()
    engineColor = 'black'
Beispiel #4
0
 def update(self):
     if self.line_to_fill == 0 and time.time(
     ) - self.end_fill_time > self.pause_before_reset_duration:
         board.reset()
         board.begin_wait_state()
     elif self.line_to_fill > 0 and time.time(
     ) - self.last_fill_time > self.fill_frequency:
         self.line_to_fill -= 1
         board.set_line(self.line_to_fill, color_indexes["death_fill"])
         self.end_fill_time = time.time()
         self.last_fill_time = time.time()
Beispiel #5
0
def start_game():
    global state
    if state != GAME_OVER:
        return

    board.reset()
    gfw.world.clear_at(gfw.layer.block)
    global score
    score.reset()
    gfw.world.remove(highscore)

    state = IN_GAME
    generate_block()
Beispiel #6
0
def main():
    global autoshow, verbose
    alphabeta.silent = False
    board.reset()
    show()
    line = raw_input(prompt)
    toks = line.split(" ")
    cmd = toks[0]
    while cmd != "quit":
        board.valid()  # agressive validation
        # find and execute command
        if cmd in ["h", "help"]:
            help()
        elif cmd in ["s", "show"]:
            show()
        elif cmd in ["l", "legals"]:
            legals()
        elif cmd in ["a", "allow"]:
            allow()
        elif cmd in ["n", "new"]:
            new()
        elif cmd in ["", "b", "best"]:
            mybest()
        elif cmd in ["r", "random"]:
            rand()
        elif cmd in ["hammer"]:
            hammer()
        elif cmd in ["showoff"]:
            autoshow = False
        elif cmd in ["showon"]:
            autoshow = True
        elif cmd in ["verboseon"]:
            verbose = True
        elif cmd in ["verboseoff"]:
            verbose = False
        elif cmd in ["find"]:
            if len(toks) == 1:
                s = raw_input("enter move> ")
            else:
                s = toks[1]
            find(s)
        elif cmd in ["u", "undo"]:
            undo()
        elif cmd in ["d", "dump"]:
            board.dump()
        else:
            trymv(cmd)
        # get next command
        line = raw_input(prompt)
        toks = line.split(" ")
        cmd = toks[0]
Beispiel #7
0
 def update(self):
     if input_manager.released_down:
         self.last_fall_time = time.time()
         if not self.is_valid_position(add_y=1):
             self.add_to_board()
     # move horizontally
     if input_manager.pressed_left:
         self.run_init_time = time.time()
         self.move_horizontal(-1)
     elif input_manager.pressed_right:
         self.move_horizontal(1)
         self.run_init_time = time.time()
     # rotation
     if input_manager.pressed_rotate_left:
         self.rotate(-1)
     elif input_manager.pressed_rotate_right:
         self.rotate(1)
     # soft and hard drops
     if input_manager.pressed_down:
         self.move_vertical()
         self.last_soft_drop_time = time.time()
     if input_manager.pressed_hard_drop:
         self.hard_drop()
     # debug, reset the board
     if input_manager.pressed_reset_board:
         board.reset()
     # fast movements
     if input_manager.pressing_left:
         self.run(-1)
     elif input_manager.pressing_right:
         self.run(1)
     if input_manager.pressing_down:
         self.soft_drop()
     elif time.time() - self.last_fall_time > self.fall_frequency:
         self.last_fall_time = time.time()
         self.move_vertical()
Beispiel #8
0
def new():
    board.reset()
    auto()
Beispiel #9
0
#!/usr/bin/python
# $Id: test.py 7 2010-01-13 12:16:47Z mark $
#
#-------------------------------------------------------------------------------
#                                      test
#-------------------------------------------------------------------------------

import man, board, move
from square import *

print "\nClear board:"
board.clear()
board.dump()

print "\nInitial position:"
board.reset()
board.dump()

print "\nClear board (again):"
board.clear()
board.dump()

print "\nInitial position (again):"
board.reset()
board.dump()

print "try to add 2nd king (two times)"
board.addMan(man.king,27)
board.addMan(-man.king,28)

BP= -man.pawn
Beispiel #10
0
def new():
    global playing
    board.reset()
    playing = True
Beispiel #11
0
    elif s == "amount" or s == "a":  # amount of solved cells
        print(str(board.get_amount_of_solved_cells()) + " cells have been solved.")

    elif s == "debug" or s == "d":
        pass

    elif s == "example" or s == "e":
        run_example()

    elif s == "solve" or s == "s":
        board.solve_sudoku()
        print(str(board.get_amount_of_solved_cells()) + " cells have been solved.")
        print(str(board))

    elif s == "solve1" or s == "s1":
        board.solve_one_cell()
        print(str(board.get_amount_of_solved_cells()) + " cells have been solved.")
        print(str(board))

    elif s == "pool" or s == "p":
        print(str(board.solution_pool))

    elif s == "guess1" or s == "g1":
        board.guess_one_cell()

    elif s == "clear" or s == "c":
        board.reset(True)

    else:
        board.add_solutions(s)