Chess and Python revisited

Similar documents
If a pawn is still on its original square, it can move two squares or one square ahead. Pawn Movement

YourTurnMyTurn.com: chess rules. Jan Willem Schoonhoven Copyright 2018 YourTurnMyTurn.com

Movement of the pieces

Welcome to the Brain Games Chess Help File.

Chess Handbook: Course One

ChesServe Test Plan. ChesServe CS 451 Allan Caffee Charles Conroy Kyle Golrick Christopher Gore David Kerkeslager

All games have an opening. Most games have a middle game. Some games have an ending.

After learning the Rules, What should beginners learn next?

The Pieces Lesson. In your chess set there are six different types of piece.

ELE 408 Final Project

Unit. The double attack. Types of double attack. With which pieces? Notes and observations

A1 Problem Statement Unit Pricing

CHESS SOLUTION PREP GUIDE.

Chapter 1: Positional Play

Chess Rules- The Ultimate Guide for Beginners

LEARN TO PLAY CHESS CONTENTS 1 INTRODUCTION. Terry Marris December 2004

Eight Queens Puzzle Solution Using MATLAB EE2013 Project

Algebraic Chess Notation

A Simple Pawn End Game

OCTAGON 5 IN 1 GAME SET

Chess, a mathematical definition

Overview... 3 Starting the Software... 3 Adding Your Profile... 3 Updating your Profile... 4

Instruction manual Chess Tutor

Boulder Chess. [0] Object of Game A. The Object of the Game is to fill the opposing Royal Chambers with Boulders. [1] The Board and the Pieces


NEW CHESS NOTATION SLAVOLJUB STOJANOVIĆ - SLLAVCCO

Essential Chess Basics (Updated Version) provided by Chessolutions.com

Chess Puzzle Mate in N-Moves Solver with Branch and Bound Algorithm

NSCL LUDI CHESS RULES

The Chess Set. The Chessboard

District Fourteen Chess Fest 2012 Information Sheet

THE COMPLETE RULES OF TIME-CUBE CHESS

DELUXE 3 IN 1 GAME SET

Structured Programming Using Procedural Languages INSS Spring 2018

12 Special Moves - Stalemate, Pawn Promotion, Castling, En Passant capture

Microchess 2.0 gives you a unique and exciting way to use your Apple II to enjoy the intellectually stimulating game of chess. The complete program lo

ARTICLE 1. THE CHESSBOARD

a b c d e f g h i j k l m n

class TicTacToe: def init (self): # board is a list of 10 strings representing the board(ignore index 0) self.board = [" "]*10 self.

NOVAG AGATE INSTRUCTION

An End Game in West Valley City, Utah (at the Harman Chess Club)

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

The Game. Getting Sarted

C SC 483 Chess and AI: Computation and Cognition. Lecture 5 September 24th

Chess for Kids and Parents

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

Technical Information - NOVAG BERYL

Its topic is Chess for four players. The board for the version I will be discussing first

Introduction 5 Algebraic Notation 6 What s So Special About the Endgame? 8

OPENING IDEA 3: THE KNIGHT AND BISHOP ATTACK

Westminster College 2012 High School Programming Contest. October 8, 2012

THROUGH THE LOOKING GLASS CHESS

Infinite chess. Josh Brunner. May 18, 2018

Your first step towards nobility

Gnome Wars User Manual

C SC 483 Chess and AI: Computation and Cognition. Lecture 3 September 10th

Cover and Interior design Olena S. Sullivan Interior format and copyediting Luise Lee

NOVAG. EMERALD CLASSIC plus INSTRUCTION

Chess Lessons in Utah

Software Requirements Specification

Homework 9: Software Design Considerations

White just retreated his rook from g7 to g3. Alertly observing an absolute PIN, your move is?

The Basic Rules of Chess

The Evergreen Game. Adolf Anderssen - Jean Dufresne Berlin 1852

John Griffin Chess Club Rules and Etiquette

White Gambits. Boris Alterman

Suggested by Joshua L. Mask. Written by Ken Mask, MD. Illustrated by Simmie Williams

BALDWIN WALLACE UNIVERSITY 2013 PROGRAMMING CONTEST

C SC 483 Chess and AI: Computation and Cognition. Lecture 2 August 27th

CPSC 217 Assignment 3


Accessory to NOVAG'S Chess Computers. Chess details

Triple Challenge.txt

Contents. Introduction 5 How to Study this Book 5

Exp. 2: Chess. 2-1 Discussion. 2-2 Objective

CHAMPIONSHIP CHESS GAME WORLD. Log On: When you log into the World of Chess, you will enter the Hall of Kings.

3. Bishops b. The main objective of this lesson is to teach the rules of movement for the bishops.

Computer Chess Programming as told by C.E. Shannon

DOWNLOAD PDF HOW TO PLAY CHESS! TACTICS, TRAPS, AND TIPS FOR BEGINNERS

How to Play Chinese Chess Xiangqi ( 象棋 )

Game-playing AIs: Games and Adversarial Search I AIMA

Here is Part Seven of your 11 part course "Openings and End Game Strategies."

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

Fun and Games on a Chess Board

Learn Chess the Right Way

Welcome & Introduction

2012 Alexey W. Root. Publisher: Mongoose Press 1005 Boylston Street, Suite 324 Newton Highlands, MA

- 10. Victor GOLENISHCHEV TRAINING PROGRAM FOR CHESS PLAYERS 2 ND CATEGORY (ELO ) EDITOR-IN-CHIEF: ANATOLY KARPOV. Russian CHESS House

2 Textual Input Language. 1.1 Notation. Project #2 2

More Adversarial Search

Augmented Reality Chess Assistance. Matthew Berntson

Tactics Time. Interviews w/ Chess Gurus John Herron Interview Tim Brennan

COMPARISON OF FIDE AND USCF RULES

Winning Chess Strategies

Part IV Caro Kann Exchange Variation

Chess for Math Curriculum

Rules of the game. chess checkers tic-tac-toe...

CS 480: GAME AI DECISION MAKING AND SCRIPTING

Contents. Part 1: General. Part 2: The Opening. Part 3: Tactics and Combinations. Introduction 6 Symbols 6

POSITIONAL EVALUATION

Transcription:

Chess and Python revisited slide 1 there exists a PyGame project http://www.pygame.org/ project-chessboard-282-.html which draws a chess board and allows users to make FIDE legal moves (by clicking on the mouse) it does not play against you the graphics are pretty and it also has a neat feature that once you highlight a piece it proceeds to highlight all legal destination squares conversely here http://floppsie.comp.glam.ac.uk/ download/m2/m2chess-0.3.tar.gz is a command line chess game which plays a very basic game of chess however ithas a horrible command line interface its redeeming virtue is that it is easy to beat!

pexpect slide 2 recall that the pexpect module can be used to allow Python to control command line programs it should be possible to modify thechessboard package to use pexpect to control them2chess program

Running m2chess from the command line slide 3 $ m2chess Enter Stage Of Game : opening Is the present Board in initial position? yes White - Computer or Human (c/h)? h Black - Computer or Human (c/h)? c The Board : abcdefgh +-----------------+ 8 rnbqkbnr 8 7 pppppppp 7 6... 6 5... 5 4... 4 3... 3 2 PPPPPPPP 2 1 RNBQKBNR 1 +-----------------+ abcdefgh

Running m2chess from the command line slide 4 Please enter move: e2e4 My move is: E7-E5 0 The Board : abcdefgh +-----------------+ 8 rnbqkbnr 8 7 pppp.ppp 7 6...s... 6 5...p... 5 4...P... 4 3... 3 2 PPPP.PPP 2 1 RNBQKBNR 1 +-----------------+ abcdefgh Please enter move:

Running m2chess from the command line slide 5 recall from lecture 11 http://floppsie.comp.glam.ac.uk/ Glamorgan//games/11.html that we can import pexpect and interact with a command line program in a similar way to that of keyboard interaction however wemust program all activity we must make our python program match output from the command line tool and provide sensible input for this tool so in the case above we need to give the appropriate initialisation parameters to the program as it starts up and respond toplease enter move: prompts and retrieve output frommy move is: statements

Running m2chess from the command line slide 6 finally any outputs need to be fed to the ChessBoard GUI and a new move need

Running m2chess from the command line slide 7 import pexpect, sys, string, os from pexpect import TIMEOUT, EOF class m2chess: def init (self, debugging = False, level = 1, filename = "./chess", directory = "."): if os.path.isdir(directory): os.chdir(directory) print "cd ", directory, " and running ", filename else: print "error as, directory: ", \ directory, " does not exist" sys.exit(0) self.child = pexpect.spawn (filename) self.child.delaybeforesend = 0 self.level = level self.finished = False self.debugging = debugging

Running m2chess from the command line slide 8 self.child.expect( Enter Stage Of Game ) self.child.sendline( opening0) if self.debugging: print self.child.before self.child.expect( Is the present Board in initial position ) self.child.sendline( yes ) if self.debugging: print self.child.before

Running m2chess from the command line slide 9 self.child.expect( Human ) self.child.sendline( h ) if self.debugging: print self.child.before self.child.expect( Human ) self.child.sendline( c ) if self.debugging: print self.child.before

Running m2chess from the command line slide 10 def makemove(self, move): if self.debugging: print "making move" print self.child.before self.child.expect( Please enter move ) self.child.sendline(move) def getmove(self): if self.debugging: print "getting move" print self.child.before i=self.child.expect([pexpect.timeout, (gdb), My move is:\s+(.*[a-h][1-8].*[a-h][1-8]) ], timeout=1000) if i==0 or i==1: print "something has gone wrong..." self.child.interact() sys.exit(0) return self.child.match.groups()[0]

Running m2chess from the command line slide 11 def dointeract(self): if self.finished: print "no m2chess interactive session available" else: try: self.child.interact() except os.error: self.finished = True

Running m2chess from the command line slide 12 def main(): foo = m2chess(false) foo.makemove( e2e4 ) print foo.getmove() foo.makemove( d2d4 ) print foo.getmove() if name == main : main()

Tutorial slide 13 using wikipedia search for Chess openings and in particular the openings starting D2-D4 (white plays Queens pawn to row 4) find the book moves which classically are used to combat this move now download m2chess-0.3.tar.gz http:// floppsie.comp.glam.ac.uk/download/m2/ m2chess-0.3.tar.gz and extract and build the file contents by typing: $ tar zxf m2chess-0.3.tar.gz $ cd m2chess $ make from a command line terminal

Tutorial slide 14 now download a modified ModifiedChessBoard.tar.gz http:// floppsie.comp.glam.ac.uk/download/m2/ ModifiedChessBoard.tar.gz and extract and run it by: $ tar zxf ModifiedChessBoard.tar.gz $ cd ModifiedChessBoard $ python PlayGame.py firstly see whether the chess program can defend against fools mate: white plays: e2-e4, f1-c4, d1-h5 and possibly h5-f7 checkmate assuming black does not defend correctly

Tutorial slide 15 and extend the filebook with these recognised replies modify the weightings (held in filein) tomakem2chess capture the center ground and also encourage the computer to castle

slide 16 Description of the evaluation function weightings there are three stages of the game of chess opening, middle game and end game each of which has the following weightings for the evaluation function: Material Balance which scores points for pawns, knights, bishops, rooks and queen ratio of 1, 3, 3, 6 and 9 the value given asthematerial Balance determines the value of a pawn

slide 17 Description of the evaluation function weightings Mobility Wgt score points for number of moves the pieces are able to make Pawn Doubled counts the number of pawns on the same column (subtracts by one) and multiplies by this value normally a negative value to encourage good pawn structure Bishop Doubled is added if a bishop is on the same diagonal as its queen encourages good piece structure, both defensive and attacking

slide 18 Description of the evaluation function weightings Rook Doubled are the two rooks on the same row orcolumn? same reason as bishop doubling Fork Pts value of a fork Can Castle can player castle Has Castled has player castled Center Control how near the center is the piece

slide 19 Description of the evaluation function weightings Near King this weighting is multiplied by the number of squares away from the king King Safety how many squares away are the enemy pieces to our king the total of this value (for each piece) is multiplied by this weighting King Center how close is the king to the center? if the king is in the center 16 squares this value is added to the evaluation function Advance Pawn avalue of 1..8 is multiplied by this weighting depending upon how close a pawn is from the end of the board

Example of Bishop Doubled slide 21 abcde fgh 8 / x x x ð\ 8 7/ xlx x x \ 7 6 / x x x x\ 6 5/ x xdx x \ 5 4 / x x x x\ 4 3/ x x x x \ 3 2 / x x x x\ 2 1/ û x x x \ 1 abcde -------- fgh

Example of Bishop Doubled slide 22 here the evaluation function adds the Bishop Doubled value to the score for black as the bishop and queen are on the same diagonal