Print pgn on side of board

This commit is contained in:
Alex Clink 2021-09-15 23:50:38 -04:00
parent 9b727ad3d5
commit 054170871f
4 changed files with 23 additions and 8 deletions

View file

@ -61,11 +61,13 @@ loop do
term.move 0, 0
print fen.to_s
term.trunc
puts
puts
term.move x: 0, y: 3
gb.draw
puts
puts
game.pgn.history.each_with_index do |san, i|
term.move game.board.width * 2 + 10, y: 3 + i
print san.to_s
end
term.move x: 0, y: game.board.height + 5
if game.turn == 0
print " #{game.full_moves + 1}. "
else

View file

@ -3,6 +3,7 @@ require "./board"
require "./notation"
require "./move_set"
require "./error"
require "./pgn"
module LxChess
# Represents a standard game of Chess
@ -16,6 +17,7 @@ module LxChess
property move_clock : Int16 = 0
property en_passant_target : Int16?
property fifty_move_rule : Int8 = 0
property pgn : PGN = PGN.new
def initialize(@board : Board = Board.new, @players = [] of Player)
end
@ -284,6 +286,7 @@ module LxChess
@board.move(from, to)
next_turn
@pgn.history << san
san
end

7
src/lx_chess/pgn.cr Normal file
View file

@ -0,0 +1,7 @@
require "./notation"
module LxChess
class PGN
property history = [] of Notation
end
end

View file

@ -23,16 +23,19 @@ module LxChess
screen_size
end
@x : Int16
@y : Int16
def initialize(@io = STDOUT)
@x = 0
@y = 0
end
# Move cursor to line, column
def move(x, y)
@x = x
@y = y
@io.print "\033[#{@x};#{@y}H"
def move(x : Int, y : Int)
@x = x.to_i16
@y = y.to_i16
@io.print "\033[#{@y};#{@x}H"
end
# Delete the rest of the line from cursor pos