Intelligence for Games and Puzzles1 Some Chess-specific Techniques Chess is played on an 8x8.

Slides:



Advertisements
Similar presentations
UIL Chess Puzzle Practice Material
Advertisements

Apostles Chess Club Lesson #4. Algebraic Chess Notation System The board is set up from white’s position. Black must look at the board from the white.
Computers playing games. One-player games Puzzle: Place 8 queens on a chess board so that no two queens attack each other (i.e. on the same row, same.
Place captured red pieces below Place captured blue pieces below Rules New Game Exit Left mouse click on piece – drag to desired location - left mouse.
Mathematical Induction II Lecture 14: Nov
Table of Contents Why Play Chess? Setting Up the Board Get to Know the Pieces Check and Checkmate What the Chess Pieces Are Worth Opening Goals Endgame.
CHESS FOR KIDS Lesson 1.
L.O. Today you will learn how to play chess. How to Play Chess.
Application of Artificial intelligence to Chess Playing Capstone Design Project 2004 Jason Cook Bitboards  Bitboards are 64 bit unsigned integers, with.
Using Graph Theory to Outsmart Opponents Ken DelSanto May 6 th 2011 Graph Theory Conference Dr. A. Beecher Ramapo College of New Jersey.
Welcome to the basics of chess. This is a graphically designed program that will help you learn how to play chess. By Amir and Mike, 9B.
Chess Variants (I) (#35) Build a 2-player Chess Game (no-AI) Make it as modular as possible, so that It is easy to adapt to game rule changes (variants)
Artificial Intelligence in Game Design Heuristics and Other Ideas in Board Games.
European Social Class and Chess By Chris Leonard.
Chapter 7 Multidimensional Arrays. Defining a two dimensional array elementType[][] arrayName; // Java pro elementType arrayName[][]; // C++ alternate.
Introduction to Chess Naming the Chess Squares Names of the Pieces Initial Setup Materials taken from Teaching Chess Step By Step manuals, Books 1 and.
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
CS1061 C Programmuing Lecture 12 Arrays A. O’Riordan, 2004.
How to play Chess.
Games and Simulations O-O Programming in Java The Walker School
COME JOIN IN ALL THE FUN Beginner Chess Club.
Chess Merit Badge Chess Basics: Set Up the Board & Basic Rules by Joseph L. Bell © 2011.
Data Structures Using C++ 2E Chapter 6 Recursion.
Apostles chess club Session 2. Chess pieces are made mostly in the Staunton style. It is the only style accepted by chess tournaments.
Aayush Garg Pecha-Kucha Design Games 10. Games I like Strategy games Mathematical games Paper and Pencil games Street games.
#2. UIL Chess Puzzle Practice Material This year’s UIL Chess Puzzle Test includes “solve the mate” positions similar to last year’s, but it also tests.
Game Playing.
Data Structures Using C++ 2E Chapter 6 Recursion.
Artificial Intelligence in Game Design Lecture 22: Heuristics and Other Ideas in Board Games.
Apostles Chess Club Session Three. Chess Piece Symbols The symbols shown above are the ones most used when showing chess pieces in print or on the internet.
Database Chess A server-based web gaming application by Jordan Arnold.
1 © 2015 B. Wilkinson Modification date: January 1, 2015 Designing combinational circuits Logic circuits whose outputs are dependent upon the values placed.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Chess and AI Group Members Abhishek Sugandhi Sanjeet Khaitan Gautam Solanki
Data Representation The storage of Text Numbers Graphics.
How to Play Chess. Name of Each Piece The relative values of the chess pieces 9 points 5 points 3+ points 3 points 1 point.
Chess By Kezia Farley.
Summary of the Moves of Chess
Lesson 1 History of Chess Why We Teach Chess Goal of Chess.
Chess By Kyle Fischer. What is chess? Chess is a game that you try to get the other person’s king in a checkmate.
A game based off of the esteemed classic By: Tadziu Kosiara.
Confidentiality/date line: 13pt Arial Regular, white Maximum length: 1 line Information separated by vertical strokes, with two spaces on either side Disclaimer.
ENEE150 – 0102 ANDREW GOFFIN Functional Decomposition.
How to play chess? By Mervyn George. The Rules of the Game White always move first White always move first You should always play touch a piece move a.
The Basics Of Chess Student Name: Jovannie Charles Date: 3/25/11.
Every chess master was once a beginner. Irving Chernev
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Chess Strategies Component Skills Strategies Prototype Josh Waters, Ty Fenn, Tianyu Chen.
Discussion 2: Intro to Project 1: Chess Submit Project 1 under # 11!
CHESS Basics for Beginners. BOARD SET-UP The letters go across the board in front of you. “White on right!” Each player has a white square in their right.
A Levoy PowerPoint Presentation
LECTURE 4 Logic Design. LOGIC DESIGN We already know that the language of the machine is binary – that is, sequences of 1’s and 0’s. But why is this?
CHESS Club.  The game of chess is over 1300 years old and is one of the most popular games in the world. It has received more total thought time than.
CHESS “The Ultimate GAME of Challenge and Strategy”
Some counting questions with the Rules of Chess. Chessboard and Chess pieces The game of chess is played on an 8-by-8 grid of alternately colored squares.
#1 Chess Engine of Spring 2017 at S&T
Ab & Team Presents CHESS “It’s not just a game”.
Ramblewood Middle Chess Club
Mathematical Induction II
How To Play Chess (And other Information)
CHESS.
Microcomputer Programming
Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the.
Chess Basics: Set Up the Board & Basic Rules
Using Bitboards for Move Generation in Shogi
Arrays, For loop While loop Do while loop
Duo By: Fernando & Vivian.
Rules to play chess. Chess is a played with 16 pieces: 8 pawns, 2 towers, 2 knights, 2 bishops, 1 queen and 1 king. Movements: Pawns: They only can move.
Presentation transcript:

Intelligence for Games and Puzzles1 Some Chess-specific Techniques Chess is played on an 8x8 board 8 is a power of two Computers are especially good at handling powers of two This happy accident has been exploited in chess programs in two main ways: move generation speedups bitboard representations

Intelligence for Games and Puzzles2 Move generation: the obvious way A natural way to represent the board is with an 8x8 array, containing values representing black pawn,... white king indexed by  rank running from 0 to 7  file running also from 0 to 7 When a chessman move is being considered, the new rank and file must satisfy rank ≥ 0 and rank ≤ 7 and file ≥ 0 and file ≤ 7 A rook can move in a ray over several empty squares, along a file {rank := rank ± n} or along a rank {file := file ± n} A bishop can move in a ray over several empty squares, along a diagonal {rank := rank ± n; file := file ± n} A queen can do either the above. Knights, Kings and (usually) Pawns do not move in rays.

Intelligence for Games and Puzzles3 Move generation with vector-based board - 1/3 It is faster to access a 1-dimensional vector than a 2-dimensional array. 8x8 board may be linearised so that 64 elements of a vector [0…63] correspond to squares a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, … g8, h8 Then a rook moves from square X to X - n (stopping after a multiple of 8) or to X + n (stopping short of multiple of 8) or to X ± 8n (stopping before going negative or going beyond 63) A bishop moves from square X to X ± 9n to X ± 7n A knight moves from square X to X±10, X±17, X±15, X±

Intelligence for Games and Puzzles4 Move generation with vector-based board - 2/3 For all piece types, the legality of moves must be checked. Checking a proposed move does not go off the top or bottom of the board is easy, just check {X ≥ 0 and X ≤ 63} Checking a proposed move does not go over the left or right edge of the board is not as easy as that; effectively you must decompose X into its rank & file components.  Can do this fairly cheaply since divide-by-8 and modulo-8 can be done with a rightshift operation and a bitwise-and operation, respectively. The top/bottom check can be made cheaper by exploiting these facts:  all numbers 0-63 have a ‘0’ in bit position 7 (from least significant)  negative numbers, and also numbers , have a ‘1’ in bit position 7  so whenever {X & 64} is non-zero then X is not valid

Intelligence for Games and Puzzles5 Move generation with vector-based board - 3/3 The board vector need not be exactly the right size. It can be bigger than needed. It is useful for it have 128 elements. (Actually only 120 is enough!) Chessboard squares can be mapped to vector elements as follows: This allows both rank and file parts of an index to be checked in one operation: indices with a ‘1’ in bit 8 are negative or greater than 127 +ve indices with a ‘1’ in bit 4 are in the range 8-15, 24-31, 48-55, …  they correspond to vector elements not mapped to any square. When (X & #x88) is nonzero X is invalid. This is the “Hex-88 Trick”. a1,b1,c1,d1,e1,f1,g1,h1,,,,,,,,,a2,b2,c2,d2,e2,f2,g2,h2, 1st rank8 unused elements2nd rank

Intelligence for Games and Puzzles6 Bitboards Rather than use a vector containing codes identifying chessmen, many programs use a collection of several 64-bit vectors, using one bit per chessboard square. The technique was pioneered by “Kaissa”, a Russian program of the 1970s which ran on a computer with 64-bit words; as today’s “Alpha” chips. Each “bitboard” uses ‘1’ bits to represent different things about a square. Making a move then involves changing at least three of these bitboards. This square is occupied. This square is occupied by a bishop. This square is occupied by white. This square is occupied by a rook. This square is occupied by black. This square is occupied by a queen. This square is occupied by a pawn. This square is occupied by a king. This square is occupied by a knight.

Intelligence for Games and Puzzles7 “Ordinary” moves of knight and king These pieces move fixed distances in any of 8 directions. They capture any enemy piece occupying their target square. There is no need to consider any squares other than source and target. For each type of piece,  and for each source bit position, –up to eight bitmaps can be constructed and stored –to represent the up-to-8 possible targets for that piece type starting from that source square If say the “d5” bit is set in the “white” and “knight” bitboards, then consider the eight d5-knight bitmaps in turn check that {WhiteBitboard & currentbitmap} is zero, if so  zero the “d5” bit in the occupied, white, & knight bitboards  zero target bit in the black, pawn, bishop, rook, queen, & king bitboards  set to one the target bit in the occupied, white, & knight bitboards

Intelligence for Games and Puzzles8 Rook moves Rooks (and Queens) can move in rays, along ranks or along files. all squares they pass over must be unoccupied the final square may be unoccupied or occupied by an enemy piece For each square, a bitmap can specify the other squares a rook (or queen) could reach if unimpeded. To see if a rook (queen) could actually reach a particular square involves checking the occupied bitboard against a substring of bits. (If a bitwise AND returns nonzero, the square cannot be reached) It is better then to use four separate bitmaps - attack bitboards - for the four different directions of movement.

Intelligence for Games and Puzzles9 Flipped bitboards Checking substrings of bits involves forming substrings of bits. This is easily done by bit-shifting when the bits in a bitstring are consecutive in memory. For the bitboard organisation shown before, that makes it easy to manipulate attack bitboards for attacks along a rank, but not along a file. By using additional bitboards, flipped on their sides, this too is made easy. a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7h7 a6b6c6d6e6f6g6h6 a5b5c5d5e5f5g5h5 a4b4c4d4e4f4g4h4 a3b3c3d3e3f3g3h3 a2b2c2d2e2f2g2h2 a1b1c1d1e1f1g1h1 h2h3h4h5h6h7h8 g1g2g3g4g5g6g7g8 f1f2f3f4f5f6f7f8 e1e2e3e4e5e6e7e8 d1d2d3d4d5d6d7d8 c1c2c3c4c5c6c7c8 b1b2b3b4b5b6b7b8 a1a2a3a4a5a6a7a8

Intelligence for Games and Puzzles10 Bishop moves Bishops (and Queens) can move in rays, along diagonals. Again, all squares they pass over must be unoccupied the final square may be unoccupied or occupied by an enemy piece For each square, a bitmap can specify the other squares a bishop (or queen) could reach if unimpeded. As before, in order to generate substrings of bits easily it would be necessary to transform the bitboards. This (complex) transformation has the name “rotated bitboard”. The term “rotated bitboard” has come to apply to flipped bitboards as well as the two transformations to follow:

Intelligence for Games and Puzzles11 Rotating a bitboard for a1…h8 1. Cut bitboard along a diagonal a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7h7 a6b6c6d6e6f6g6h6 a5b5c5d5e5f5g5h5 a4b4c4d4e4f4g4h4 a3b3c3d3e3f3g3h3 a2b2c2d2e2f2g2h2 a1b1c1d1e1f1g1h1

Intelligence for Games and Puzzles12 Rotating a bitboard for a1…h8 1. Cut bitboard along a diagonal 2. Rearrange halves to make parallelogram a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7h7 a6b6c6d6e6f6g6h6 a5b5c5d5e5f5g5h5 a4b4c4d4e4f4g4h4 a3b3c3d3e3f3g3h3 a2b2c2d2e2f2g2h2 a1b1c1d1e1f1g1h1 h7 g6h6 f5g5h5 e4f4g4h4 d3e3f3g3h3 c2d2e2f2g2h2 b1c1de1f1g1h1 a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7 a6b6c6d6e6f6 a5b5c5d5e5 a4b4c4d4 a3b3c3 a2b2 a1

Intelligence for Games and Puzzles13 Rotating a bitboard for a1…h8 1. Cut bitboard along a diagonal 2. Rearrange halves to make parallelogram 3. Squash to make new square a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7h7 a6b6c6d6e6f6g6h6 a5b5c5d5e5f5g5h5 a4b4c4d4e4f4g4h4 a3b3c3d3e3f3g3h3 a2b2c2d2e2f2g2h2 a1b1c1d1e1f1g1h1 h7 g6h6 f5g5h5 e4f4g4h4 d3e3f3g3h3 c2d2e2f2g2h2 b1c1d1e1f1g1h1 a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7 a6b6c6d6e6f6 a5b5c5d5e5 a4b4c4d4 a3b3c3 a2b2 a1 a8b1c2d3e4f5g6h7 a7b8c1d2e3f4g5h6 a6b7c8d1e2f3g4h5 a5b6c7d8e1f2g3h4 a4b5c6d7e8f1g2h3 a3b4c5d6e7f8g1h2 a2b3c4d5e6f7g8h1 a1b2c3d4e5f6g7h8

Intelligence for Games and Puzzles14 Rotating a bitboard for a8…h1 1. Cut bitboard along a diagonal 2. Rearrange halves to make parallelogram 3. Squash to make new square a8b8c8d8e8f8g8h8 a7b7c7d7e7f7g7h7 a6b6c6d6e6f6g6h6 a5b5c5d5e5f5g5h5 a4b4c4d4e4f4g4h4 a3b3c3d3e3f3g3h3 a2b2c2d2e2f2g2h2 a1b1c1d1e1f1g1h1 a7 a6b6 a5b5c5 a4b4c4d4 a3b3c3d3e3 a2b2c2d2e2f2 a1b1c1d1e1f1g1 a8b8c8d8e8f8g8h8 b7c7d7e7f7g7h7 c6d6e6f6g6h6 d5e5e6g5h5 e4f4g4h4 f3g3h3 g2h2 h1 a7b6c5d4e3f2g1h8 a6b5c4d3e2f1g8h7 a5b4c3d2e1f8g7h6 a4b3c2d1e8f7g6h5 a3b2c1d8e7f6g5h4 a2b1c8d7e6f5g4h3 a1b8c7d6e5f4g3h2 a8b7c6d5e4f3g2h1

Intelligence for Games and Puzzles15 Using rotated bitboards Programs that use rotated bitboards do so for the sake of efficiency of the logic for move generation and attack detection. They use many precomputed bitboards, using memory to gain speed. Whenever a move is made, a few more bitboards must be kept up to date: Regular file-oriented bitboards, for occupied, white, black, pawn etc.  often separating further: blackpawn, whitepawn, blackknight, … Flipped, rank-oriented versions of all of those. Rotated a1-h8 versions, and Rotated a8-h1 versions With true 64-bit machine words, the bitwise operations are very fast. With 32-bit words, even if a language allows 64-bit integers, benefits are less.

Intelligence for Games and Puzzles16 Some online references supertech.lcs.mit.edu/~heinz/dt/node8.html (beware, rank & file confused in 1st paragraph) atlanchess.com/html/rotated_bitboards.html