anti-chess and a.i

Upload: manik-jindal

Post on 16-Oct-2015

132 views

Category:

Documents


0 download

DESCRIPTION

Anti Chess a popular variant of Chess. And it's A I, heuristic function.

TRANSCRIPT

  • Anti-Chess

    And

    Artificial Intelligence (Major Project Part-I)

    Manik Jindal

    2K10/CO/054

  • Contents

    1. Acknowledgement

    2. Aims and Objectives

    3. Review of Literature

    a. Introduction to Logic Games

    b. Solved Logic Games

    c. The MinMax Algorithm

    d. MinMax algorithm with Alpha-Beta pruning

    4. Introduction to Anti-Chess

    a. Rules

    b. Similar Variants

    c. Differences to Normal Chess

    5. Anti-Tic-Tac-Toe

    6. GUI implementation as a multiplayer Web-Application

    7. KPantas Losers Chess

    a. The Algorithm

    b. The Heuristics

    8. Future Plan of Action

    9. References

    10. Appendix I

    11. Appendix II

    12. Appendix III

  • Acknowledgement

    I take this opportunity to express my profound gratitude and deep

    regards to my project guide, Prof. Daya Gupta, HoD Computer

    Engineering, Delhi Technological University, for her exemplary

    guidance, monitoring and constant encouragement throughout the

    course of this training. Her continued blessings and guidance shall carry

    me a long way in the Computer Engineering field.

  • Aims and Objectives

    1. To bridge the gap of our understanding in combinatorial game theory

    about games with branching factor which varies heavily. Such as the

    games employing forced-moves.

    2. To research and implement an all-intelligent computer player for the

    Game, Anti-Chess.

    3. To make this algorithm available online as a GUI for users around the

    world to play and strengthen the A.I.

    4. To contribute to the research of the Anti-Chess community worldwide, a

    relatively new field.

  • Review of Literature

    Introduction to Logic Games

    A Logic Game is a game in which the number of possible moves at any given

    point of time in the game is bound by certain logical constraints and hence the

    number of moves is finite and the next move will belong to that set of moves.

    Examples of Logic games are many like Chess, Checkers, Go, Tic-Tac-Toe,

    Connect 4, Reversi, etc.

    The Logical Constraints incorporate the physical limitations of the game and

    they robustly define and implement the rules of the game in logical definitions.

    A two-player game is a game played between two independent entities (We

    do not deal with Coalitions).

    A Zero-Sum game is a game in which one players victory is equal to the

    others loss that is there are no cooperative victories.

    Cooperative or non-cooperative

    A game is cooperative if the players are able to form binding commitments.

    For instance the legal system requires them to adhere to their promises. In non-

    cooperative games this is not possible.

    Symmetric and asymmetric

    Symmetric game is a game where the payoffs for playing a particular strategy

    depend only on the other strategies employed, not on who is playing them. If

    the identities of the players can be changed without changing the payoff to the

    strategies, then a game is symmetric.

    Simultaneous games are games where both players move simultaneously, or

    if they do not move simultaneously, the later players are unaware of the earlier

    players actions (making them effectively simultaneous).

  • Sequential games (or dynamic games) are games where later players have

    some knowledge about earlier actions. This need not be perfect information

    about every action of earlier players; it might be very little knowledge. For

    instance, a player may know that an earlier player did not perform one

    particular action, while he does not know which of the other available actions

    the first player actually performed.

    An important subset of sequential games consists of games of perfect

    information. A game is one of perfect information if all players know the

    moves previously made by all other players. Thus, only sequential games can

    be games of perfect information, since in simultaneous games not every player

    knows the actions of the others.

    Perfect information is often confused with complete information, which is a

    similar concept. Complete information requires that every player know the

    strategies and payoffs available to the other players but not necessarily the

    actions taken.

    Infinitely long games

    Games, as studied by economists and real-world game players, are generally

    finished in finitely many moves. Pure mathematicians are not so constrained,

    and set theorists in particular study games that last for infinitely many moves,

    with the winner (or other payoff) not known until after all those moves are

    completed.

    Discrete and continuous games

    Much of game theory is concerned with finite, discrete games that have a finite

    number of players, moves, events, outcomes, etc. Many concepts can be

    extended, however. Continuous games allow players to choose a strategy from

    a continuous strategy set.

    Examples of game that have finite number of possible moves but are not logical

    games: Rock-Paper-Scissors, Coin flipping

  • Solved Logic Games

    A solved game is a game whose outcome (win, lose, or draw) can be correctly

    predicted from any position when each side plays optimally.

    In game theory, perfect play is the behaviour or strategy of a player which

    leads to the best possible outcome for that player regardless of the response by

    the opponent. Based on the rules of a game, every possible final position can

    be evaluated (as a win, lose or draw). By backward reasoning, one can

    recursively evaluate a non-final position as identical to that of the position that

    is one move away and best valued for the player whose move it is.

    Thus a transition between positions can never result in a better evaluation for

    the moving player and a perfect move in a position would be a transition

    between positions that are equally evaluated. As an example, a perfect player

    in a drawn position would always get a draw or win, never a loss. If there are

    multiple options with the same outcome, perfect play is sometimes considered

    the fastest method leading to a good result, or the slowest method leading to a

    bad result.

    A two-player game can be solved on several levels:

    1. Ultra-weak

    In the weakest sense, solving a game means proving whether the first

    player will win, lose, or draw from the initial position, given perfect play

    on both sides. This can be a non-constructive proof (possibly involving

    a strategy stealing argument) that need not actually determine any moves

    of the perfect play.

    2. Weak

    More typically, solving a game means providing an algorithm that

    secures a win for one player, or a draw for either, against any possible

    moves by the opponent, from the beginning of the game. That is,

    producing at least one complete ideal game (all moves start to end), with

    proof that each move is optimal for the player making it.

  • 3. Strong

    The strongest sense of solution requires an algorithm which can produce

    perfect play (moves) from any position, i.e. even if mistakes have

    already been made on one or both sides.

    Given the rules of any two-person game with a finite number of positions, one

    can always trivially construct a MinMax tree that would exhaustively traverse

    the game tree. However, since for many non-trivial games such an algorithm

    would require an infeasible amount of time to generate a move in a given

    position, a game is not considered to be solved weakly or strongly unless the

    algorithm can be run by existing hardware in a reasonable time. Many

    algorithms rely on a huge pre-generated database, and are effectively nothing

    more than that.

    Example, the game of tic-tac-toe is solvable as a draw for both players with

    perfect play (a result even manually determinable by schoolchildren).

  • The MinMax Algorithm

    MinMax (sometimes MiniMax), is a decision rule used in decision theory,

    game theory, statistics and philosophy for minimizing the possible loss for a

    worst case (maximum loss) scenario. Alternatively, it can be thought of as

    maximizing the minimum gain (maximin or MaxMin).

    Originally formulated for two-player zero-sum game theory, covering both the

    cases where players take alternate moves and those where they make

    simultaneous moves, it has also been extended to more complex games and to

    general decision making in the presence of uncertainty.

    The MinMax theorem states:

    For every two-person, zero-sum game with finitely many strategies, there

    exists a value V and a mixed strategy for each player, such that

    a. Given player 2s strategy, the best payoff possible for player 1 is V,

    b. Given player 1s strategy, the best payoff possible for player 2 is

    V.

    Equivalently, Player 1s strategy guarantees him a payoff of V regardless of

    Player 2s strategy, and similarly Player 2 can guarantee himself a payoff of

    V.

  • The name MinMax arises because each player minimizes the maximum payoff

    possible for the othersince the game is zero-sum, he also minimizes his own

    maximum loss (i.e. maximize his minimum payoff).

    A MinMax algorithm is a recursive algorithm for choosing the next move in

    an n-player game, usually a two-player game. A value is associated with each

    position or state of the game. This value is computed by means of a position

    evaluation function and it indicates how good it would be for a player to reach

    that position. The player then makes the move that maximizes the minimum

    value of the position resulting from the opponents possible following moves.

    The algorithm can be thought of as exploring the nodes of a game tree. The

    effective branching factor of the tree is the average number of children of each

    node (i.e., the average number of legal moves in a position). The number of

    nodes to be explored usually increases exponentially with the number of plies

    (it is less than exponential if evaluating forced moves or repeated positions).

    The number of nodes to be explored for the analysis of a game is therefore

    approximately the branching factor raised to the power of the number of plies.

    It is therefore impractical to completely analyse games such as chess using the

    MinMax algorithm.

    The performance of the nave MinMax algorithm may be improved

    dramatically, without affecting the result, by the use of alpha-beta pruning.

    Other heuristic pruning methods can also be used, but not all of them are

    guaranteed to give the same result as the un-pruned search.

    A nave MinMax algorithm may be trivially modified to additionally return an

    entire Principal Variation along with a MinMax score.

  • Alpha-Beta Pruning

    Alphabeta pruning is a search algorithm that seeks to decrease the number of

    nodes that are evaluated by the MinMax algorithm in its search tree. It is an

    adversarial search algorithm used commonly for machine playing of two-

    player games (Tic-tac-toe, Chess, Go, etc.). It stops completely evaluating a

    move when at least one possibility has been found that proves the move to be

    worse than a previously examined move. Such moves need not be evaluated

    further. When applied to a standard MinMax tree, it returns the same move as

    MinMax would, but prunes away branches that cannot possibly influence the

    final decision.

    Alpha-beta pruning gets its name from two bounds that are passed along during

    the calculation, which restrict the set of possible solutions based on the portion

    of the search tree that has already been seen. Specifically,

    Beta is the minimum upper bound of possible solution

    Alpha is the maximum lower bound of possible solutions

    Thus, when any new node is being considered as a possible path to the solution,

    it can only work if:

  • Where N is the current estimate of the value of the node.

  • Introduction to Anti-Chess

    Anti-Chess (also known as Losing chess, the Losing Game, Giveaway chess,

    Suicide chess, Killer chess, or Take-all chess) is a chess variant in which the

    objective of each player is to lose all of his pieces, that is, a misre version. It is

    one of the most popular of all chess variants.

    The origin of the game is unknown, but believed to significantly pre-date an early

    version, named Take Me, played in the 1870s. Because of the popularity of Anti-

    Chess, several variations have spawned.

    Rules

    The rules of the game are the same as those of chess except for the following

    additional rules:

    Capturing is compulsory.

    When more than one capture is available, the player may exercise choice.

    The king has no special prerogative and accordingly:

    o It may be captured like any other piece.

    o There is no check or checkmate.

    o There is no castling.

    o Pawns may also promote to King.

    In the case of stalemate, there are different rules:

    o It is a win for the stalemated player (international rules).

    o It is a draw.

    o It is a win for the player with the fewer number of pieces, and if both

    have the same number it is a draw. The type of the piece makes no

    difference (FICS rules).

    A player wins by losing all his pieces, or being stalemated (as detailed.) Apart

    from move repetition, mutual accord and the fifty-move rule, the game is also

    drawn when a win is impossible, such as if a dark-squared bishop and a light-

    squared bishop are the only pieces remaining.

    Because of the forced capture rule, Anti-Chess games often involve long

    sequences of forced captures by one player. This means that a minor mistake

    can ruin the game. Losing openings include 1.d4, 1.e4, 1.d3, 1.Nc3, 1.Nf3,

    1.f4, 1.h4, 1.b4, 1.h3. Some of these openings took months of computer time

    to solve, but the wins against 1.d3, 1.d4, and 1.e4 consist of a single series of

    forced captures and can be played from memory by most experienced players.

  • Similar Variants

    Losers Chess: Losing chess (Suicide chess) has been a popular chess

    variant on most chess servers that have offered it ever since the early

    days of the ICS. There are two major variants played online, Losers

    Chess played on ICC, which actually created the variant because they

    were unable to implement the free ICSs Suicide chess rules. The goal

    in both games is to lose all of ones pieces, although in Losers Chess, a

    player can also win by getting checkmated.

    Kamikaze Chess:

    o A player wins by losing all his pieces, or by checkmating the

    opponent.

    o The king has royal powers, and removing check takes precedence

    over capturing.

    o Players must lose their king last. Players must not move into

    check until they have only the king left.

    o Pawns promote only to queens.

    Differences to Normal Chess:

    1. Although the pieces move in the same way as in Chess, in Anti-Chess,

    the restriction to capture a piece, if the player can, amounts to long

    sequences of forced-captures.

    2. Forced-Captures can turn the game around for the losing player very

    quickly.

    3. The End-Games are particularly varied.

    4. Forced Captures lead to quicker games. An Average Anti-Chess game

    may last only up to 1/10th the time taken by an average Chess game.

  • Anti-Tic-Tac-Toe

    In the pursuit of developing Artificial Intelligence for Anti-Chess, a small

    experiment was done with the traditional Tic-Tac-Toe on the same lines as Anti-

    Chess, called Anti-Tic-Tac-Toe.

    The experiment was undertaken to assess future challenges in developing an all-

    intelligent computer player for Anti-Chess and to get a fair idea of the possible

    methods to tackle the problem at hand.

    The steepest-ascent hill climbing method was successfully implemented for the

    game. The evaluation function is given below.

    1. There are 8 lines, in which a player can win. (3 Horizontal, 3 Vertical

    and 2 Diagonal).

    2. Let X be the computer player, and O be the opponent, then:

    a. Assign a line +10 if there is just a single X in it.

    b. Assign a line +100 is there are just two Xs in it.

    c. Assign a line +1000 if there are three Xs in it.

    d. Assign a line -10 if there is just a single O in it.

    e. Assign a line -100 if there are just two Os in it.

    f. Assign a line -1000 if there are three Os in it.

    g. If a line has both X and O assign it the value 0.

    3. Total all the values assigned and negate the result, this gives us the

    evaluation for the state.

    4. Chose the next state which maximises the difference in the evaluation

    value of the current state and the next state.

    The Code base to the implementation is attached at Appendix I.

  • GUI implementation as a Web-

    Application

    A major challenge in the success of any game-related A.I. is that it will always

    be beaten by players around the world who do not think conventionally,

    especially in a game such as Anti-Chess.

    To tackle this, we are implementing a web-application to be hosted on the

    internet that allows real-time players to compete with our A.I. and generate

    useful test cases for us to analyse.

    This being pursued with the highest of enthusiasm using Googles App engine

    with python and webapp2 (web-framework) to make this project up and running

    as soon as possible.

    The implementation is in its final stages with a handful of bugs to be removed

    and features to be added. Its code base is attached in Appendix II.

  • KPantas Losers Chess

    In the quest to implement an all-intelligent computer player for Anti-Chess, we

    decided to study projects available as open-source literature. One such project is

    KPantas Losers Chess.

    With particular interest in the A.I. we analysed the following.

    The Algorithm

    1. KPantas Losers Chess implements an alpha-beta pruned MinMax

    tree, up to an average depth of 8 plies.

    2. The evaluation function consists of 4 factors:

    a. Material Value: The innate value associated with each piece on the

    board

    b. Positional Value: The value of the piece at a particular position on

    the board

    c. Castling Value: The arrangement of the board w.r.t to a King being

    Castled

    d. Extra Bonus: Some particular arrangements of the board offering

    known advantage to the player.

    3. The final value of the state is given by (Material Value + Positional

    Value)*10 + Castling Value + Extra bonus.

    The Heuristics

    The Heuristic values of KPantas Losers Chess is given out as position matrix

    for each piece on the board. It is attached in Appendix III.

  • Future Plan of Action

    1. To complete the GUI implementation as a web-application and host it

    on the internet within a month.

    2. To study various heuristics used in Chess and draw a parallel for Anti-

    Chess.

    3. To Study and analyse various heuristics developed, for their flaws

    (both big and small) and their strong points.

    4. To finally arrive at a versatile algorithm/heuristic function as an all-

    intelligent computer player for Anti-Chess.

  • References

    1. http://wikipedia.org

    2. http://catalin.francu.com/nilatac/book.php

    3. http://www.princeton.edu/~achaney/tmve/wiki100k/docs/Antichess.html

    4. http://ilk.uvt.nl/icga/games/losingchess/

    5. http://www.jsbeasley.co.uk/vchess/losingendlit.pdf

    6. http://suicidechess.ca/index.php

    7. http://scidb.sourceforge.net/index.html

  • Appendix I

  • Appendix II

  • Appendix III