Add fromX, fromY to queen move

This commit is contained in:
ekzyis 2024-09-26 10:40:29 +02:00
parent 0175ac077f
commit 2dc7cbf213
1 changed files with 4 additions and 3 deletions

View File

@ -326,7 +326,7 @@ func (b *Board) Move(move string) error {
case "n": case "n":
return b.moveKnight(to, fromX, fromY) return b.moveKnight(to, fromX, fromY)
case "q": case "q":
return b.moveQueen(to) return b.moveQueen(to, fromX, fromY)
case "k": case "k":
return b.moveKing(to, castle) return b.moveKing(to, castle)
default: default:
@ -1117,16 +1117,17 @@ func (b *Board) moveKnight(position string, fromX int, fromY int) error {
return fmt.Errorf("no knight found that can move to %s", position) return fmt.Errorf("no knight found that can move to %s", position)
} }
func (b *Board) moveQueen(position string) error { func (b *Board) moveQueen(position string, fromX int, fromY int) error {
var ( var (
err error err error
) )
// TODO: queen bishop moves might be ambiguous if there are multiple queens
if err = b.moveBishop(position, true); err == nil { if err = b.moveBishop(position, true); err == nil {
return nil return nil
} }
if err = b.moveRook(position, true, -1, -1); err == nil { if err = b.moveRook(position, true, fromX, fromY); err == nil {
return nil return nil
} }