LordDarkula/chess_py

View on GitHub
chess_py/players/player.py

Summary

Maintainability
A
0 mins
Test Coverage
# -*- coding: utf-8 -*-

"""
Parent class of chess engines built on chess_py. This class must be inherited
and abstract method ``generate_move(self, position) must be implemented.``.
"""

from abc import ABCMeta, abstractmethod
from pip._vendor.distlib.compat import raw_input
import sys


class Player:
    __metaclass__ = ABCMeta

    def __init__(self, input_color):
        """
        Creates interface for base player.

        :type: input_color: Color
        """
        self.color = input_color

    @abstractmethod
    def generate_move(self, position):
        """
        Must be implemented by classes that extend ``Player``.
        Must return object of type ``Move``.

        :type: position: Board
        :rtype: Move
        """
        pass

    @staticmethod
    def getUCI():
        """
        Internal method used by ``Interface``
        to read UCI commands from external GUI.

        :rtype: str
        """
        return sys.stdin.read()

    @staticmethod
    def setUCI(command):
        """
        Internal method used by ``Interface``
        to write UCI commands to the console so they
        can be read by external GUI.

        :type: command: str
        """
        sys.stdout.write(command)