AttackingOrDefending / pydraughts

A draughts (checkers) library for Python with move generation, PDN reading and writing, engine communication and balloted openings
MIT License
14 stars 5 forks source link

Black always starts in American checkers/English draughts #26

Closed bcorfman closed 2 years ago

bcorfman commented 2 years ago

If I create a new game with g = Game(variant='english') and then type g.whose_turn() the answer is 2 (WHITE).

AttackingOrDefending commented 2 years ago

This was added to make the code simpler.

White always starts. Black always has the squares starting from 1 (e.g. 1-20 in international draughts).

To convert to the other side you can use 3 - g.whose_turn() for now.

I will add this feature in the next version. Possibly something like game.variant_turn or maybe an entire new class VariantGame, so the correct color will start and the fen and move will be in the standard notation.

In convert.py there are functions you can use to convert to the each variants standard fen/move. For example:

from draughts import Game, Move
from draughts.convert import fen_to_variant, fen_from_variant, move_from_variant, move_to_variant

g = Game(variant='english')
internal_fen = g.get_li_fen()

standard_english_fen = fen_to_variant(internal_fen, 'english')
back_to_internal_fen = fen_from_variant(standard_english_fen, 'english')

standard_english_move = '11-15'
internal_move = Move(pdn_move=move_from_variant(move, g.variant), board=g)
back_to_english_move = move_to_variant(internal_move.pdn_move, 'english')
bcorfman commented 2 years ago

Hey, thanks for responding. I admit I haven't delved into your code, but I hope the fix wouldn't involve more than a very modest change. American checkers still starts with black on squares 1-12 and white on squares 21-32; it's just that black moves first.

AttackingOrDefending commented 2 years ago

You can try #27. It implements all these features. Now you can input moves as normal:

from draughts import Board, Move
board = Board('english')
move = Move(board, pdn_move='9-13')
board.push(move)