Code Monkey home page Code Monkey logo

chess's Introduction

Chess

Expects input in algebraic chess notation.

To play, load chess.rb in irb/pry, and:

g = Game.new

g.play

#Game code structure

##Pieces ####Sliding pieces (bishop/rook/queen)

  • SlidingPiece can implement #moves.
  • Each subclass will need #move_dirs, an array of deltas that stores directions.

####Stepping pieces (knight/king)

  • SteppingPiece can implement #moves.
  • Each subclass will need #deltas.

####The pawn TODO

##Methods of Piece:

  • is_on_board? checks if a move is on the board
  • valid_moves returns all moves that do not put the player into check
    • calls moves, selects from what it returns
  • moves_into_check?(pos)
    • calls board.dup and board.in_check?
  • move
    • checks if the move is valid
      • if the move is valid (does not put the player into check)
      • so: calls valid_moves

##Methods of SlidingPiece:

  • moves
    • returns all possible moves

##Methods of SteppingPiece:

  • moves

##Methods of Board:

  • in_check?
  • move(start, end_pos)

will raise some exceptions under the conditions given

will call the piece's move method dup

##Player

###HumanPlayer

###ComputerPlayer

  • Generate a tree of all moves up to a certain depth. Assume opponent does the same.
    • Recursive depth-first search.
  • Once you reach the base case, return a score.
    • How will the score be calculated?
    • Can use conventional piece values to calculate utility of captures.
    • Assign a large value to check.
    • Fractional values for control of the center?
    • On checkmate, return an arbitrarily large value to ensure you do that.
    • White takes a positive value; black takes a negative value.
  • For other cases than the base, process the scores returned by previous cases.
    • How will this work?
  • Can optimize by pruning obviously bad moves.
    • If you can be checkmated, don't search that branch anymore.

chess's People

Contributors

defseg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.