예제 #1
0
    def setup(self, ):
        for i in range(4):
            for j in range(5):
                if i == 0:
                    pos = {
                        0: CHARIOT,
                        1: HORSE,
                        2: ELEPHANT,
                        3: ADVISOR,
                        4: GENERAL
                    }
                elif i == 2:
                    pos = {1: CANNON}
                elif i == 3:
                    pos = {0: SOLDIER, 2: SOLDIER, 4: SOLDIER}
                else:
                    pos = {0: 0}
                try:
                    p = pos[j]
                except:
                    p = 0
#                print (p)
# side == 0 indicate top side
# else bottom side
                side = 0

                if p != 0:
                    self.board[i * 9 + j] = chess.chess(side, p, [i, j])
                    self.board[i * 9 + 8 - j] = chess.chess(
                        side, p, [i, 8 - j])

                    self.side0.append(self.board[i * 9 + j])
                    if i * 9 + j != i * 9 + 8 - j:
                        self.side0.append(self.board[i * 9 + 8 - j])

                    side = 1
                    self.board[(9 - i) * 9 + j] = chess.chess(
                        side, p, [9 - i, j])
                    self.board[(9 - i) * 9 + 8 - j] = chess.chess(
                        side, p, [9 - i, 8 - j])

                    self.side1.append(self.board[(9 - i) * 9 + j])
                    if (9 - i) * 9 + 8 - j != (9 - i) * 9 + j:
                        self.side1.append(self.board[(9 - i) * 9 + 8 - j])

                    if (i == 0 or i == 9) and j == 4:
                        self.general0 = self.board[4]
                        self.general1 = self.board[9 * 9 + 4]
                else:
                    self.board[i * 9 + j] = 0
예제 #2
0
 def __init__(self, color):
     #print("Valar Morghulis")
     self.chess = chess.chess()
     self.name = self.__class__.__name__.lower()
     if color == 'black':
         self.name = self.name.lower()
     elif color == 'white':
         self.name = self.name.upper()
     self.color = color
예제 #3
0
def judge():
    global board, id0, id1, ai0, ai1, name0, name1, color_ai, steps, Record, init_board

    # start working
    steps = 0
    now_sit = 0
    Record = []
    init_board = []
    board = chess.chess()

    # record chess
    Record_Chess()

    # spawn AI
    seed_base = int(time.time() * 1e3) % 10000000000
    id0 = seed_base % 2
    id1 = 1 - id0
    color_ai = [None, None]
    color_ai[0] = 0 if id0 == 0 else 1
    color_ai[1] = 1 - color_ai[0]
    ai0 = spawnAI([sys.argv[1], '%.0f' % (seed_base+0)])
    ai1 = spawnAI([sys.argv[2], '%.0f' % (seed_base+1)])
    check_both(type(ai0) is not dict, type(ai1) is not dict, ai0, ai1)

    # send ID and get name
    res0 = send_id(ai0, id0)
    res1 = send_id(ai1, id1)
    name0 = res0 if type(res0) is not dict else '[Unknown]'
    name1 = res1 if type(res1) is not dict else '[Unknown]'
    check_both(type(res0) is not dict, type(res1) is not dict, res0, res1)

    while steps < 2000:
        steps += 1
        if now_sit == 0:
            res1 = action(ai0)
            Record.append(res1)
            check_both('err' not in res1, True, res1,'')
            
            work(id0, res1)
            message(ai0, id0, res1)
            message(ai1, id0, res1)

            now_sit = now_sit^1
        else:
            res2 = action(ai1)
            Record.append(res2)
            check_both(True, 'err' not in res2, '', res2)

            work(id1, res2)
            message(ai0, id1, res2)
            message(ai1, id1, res2)

            now_sit = now_sit^1

    # stpes exceeded
    finish(2, 'steps exceeded', 'steps exceeded')
예제 #4
0
def judge():
    global board, id0, id1, ai0, ai1, name0, name1, color_ai, steps, Record, init_board

    # start working
    steps = 0
    now_sit = 0
    Record = []
    init_board = []
    board = chess.chess()

    # record chess
    Record_Chess()

    # spawn AI
    seed_base = int(time.time() * 1e3) % 10000000000
    id0 = seed_base % 2
    id1 = 1 - id0
    color_ai = [None, None]
    color_ai[0] = 0 if id0 == 0 else 1
    color_ai[1] = 1 - color_ai[0]
    ai0 = spawnAI([sys.argv[1], '%.0f' % (seed_base + 0)])
    ai1 = spawnAI([sys.argv[2], '%.0f' % (seed_base + 1)])
    check_both(type(ai0) is not dict, type(ai1) is not dict, ai0, ai1)

    # send ID and get name
    res0 = send_id(ai0, id0)
    res1 = send_id(ai1, id1)
    name0 = res0 if type(res0) is not dict else '[Unknown]'
    name1 = res1 if type(res1) is not dict else '[Unknown]'
    check_both(type(res0) is not dict, type(res1) is not dict, res0, res1)

    while steps < 600:
        steps += 1
        if now_sit == 0:
            res1 = action(ai0)
            Record.append(res1)
            check_both('err' not in res1, True, res1, '')

            work(id0, res1)
            message(ai0, id0, res1)
            message(ai1, id0, res1)

            now_sit = now_sit ^ 1
        else:
            res2 = action(ai1)
            Record.append(res2)
            check_both(True, 'err' not in res2, '', res2)

            work(id1, res2)
            message(ai0, id1, res2)
            message(ai1, id1, res2)

            now_sit = now_sit ^ 1

    # stpes exceeded
    finish(2, 'steps exceeded', 'steps exceeded')
예제 #5
0
 def __init__(self,window):
     self.all_squares_to_be_highlighted = None
     self.chess=chess.chess()
     self.images={}
     self.selected_piece_position = None
     self.window=window
     self.BOARD_COLOR_1 = BOARD_COLOR_1
     self.BOARD_COLOR_2 = BOARD_COLOR_2
     self.create_chess_base()
     self.canvas.bind("<Button-1>", self.on_square_clicked)
     self.start_new_game()
예제 #6
0
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 01 22:43:57 2014

@author: Juda
@email: [email protected]
"""

import network
import record
import chess

log=record.record()
server=network.server(log)
board=chess.chess(log)

log.logging("Game Begin",'SHOWALL')

now_player=1
player_limit=[3,3]

steps=0
while True:
    steps+=1
    now_player=1-now_player;
    server.send(server.AI[now_player],'action')
    log.logging("Send to player %d [name: %s] a signal: ACTION"%(now_player,server.AIname[now_player]))
    try:
        message=server.recieve(server.AI[now_player])
    except socket.timeout:
        log.logging("Recieve message form player %d [name: %s]: TIME EXCEEDED LIMIT"%(now_player,server.AIname[now_player]),'SHOWALL')
예제 #7
0
def judge():
    global board, id0, id1, ai0, ai1, name0, name1, color_ai, steps, empty_steps, init_board, init0, init1, Record, first_sit

    # spawn AI
    seed_base = int(time.time() * 1e3) % 10000000000
    id0 = 0
    id1 = 1 - id0
    color_ai = [0, 0]
    color_ai[0] = 0
    color_ai[1] = 1
    ai0 = spawnAI([sys.argv[1], '%.0f' % (seed_base + 0)], 'ai0_stdin.log',
                  'ai0_stdout.log', 'ai0_stderr.log')
    ai1 = spawnAI([sys.argv[2], '%.0f' % (seed_base + 1)], 'ai1_stdin.log',
                  'ai1_stdout.log', 'ai1_stderr.log')
    check_both(type(ai0) is not dict, type(ai1) is not dict, ai0, ai1)
    # send ID and get name
    res0 = send_id(ai0, 0)
    res1 = send_id(ai1, 1)
    name0 = res0 if type(res0) is not dict else '[Unknown]'
    name1 = res1 if type(res1) is not dict else '[Unknown]'
    check_both(type(res0) is not dict, type(res1) is not dict, res0, res1)
    # start working
    steps = 0
    empty_steps = 0
    first_sit = 0
    now_sit = 0
    Record = []
    init_board = []
    init0 = get_init(ai0)
    init1 = get_init(ai1)
    check_both(type(init0) is not dict, type(init1) is not dict, init0, init1)

    board = chess.chess(init0, init1)
    show_init(ai0)
    show_init(ai1)

    # record chess
    Record_Chess()

    eat_occurs = False
    while empty_steps < 50:
        steps += 1
        eat_occurs = False
        print("now it's the %d-th step" % steps)
        if now_sit == 0:
            res1 = action(ai0)
            Record.append(res1)
            check_both('err' not in res1, True, res1, '')
            eat_occurs = work(id0, res1)
            message(ai0, id0, res1)
            message(ai1, id0, res1)
            if eat_occurs:
                empty_steps = 0
            else:
                empty_steps += 1
            now_sit = now_sit ^ 1
        else:
            res2 = action(ai1)
            Record.append(res2)
            check_both(True, 'err' not in res2, '', res2)
            eat_occurs = work(id1, res2)
            message(ai0, id1, res2)
            message(ai1, id1, res2)
            if eat_occurs:
                empty_steps = 0
            else:
                empty_steps += 1
            now_sit = now_sit ^ 1

    # steps exceeded
    finish(2, 'steps exceeded', 'steps exceeded')
예제 #8
0
# Tests the chess function
# Mostly saves a lot of time.  

import chess
game = chess.chess()