-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
executable file
·113 lines (81 loc) · 2.74 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
local cute = require("cute")
local shapes = require("src.shapes")
require 'Board'
require 'Bot'
require 'Positions'
local array = require 'lib.array'
local inspect = require 'lib.inspect'
local hasTurn = 'white'
clickedPieceIndex = nil
-- Pieces = {}
-- Pieces = PieceFactory:spawnPosition(Positions.empty)
chessBoard = Board:new('white')
bot = Bot:new()
function love.load(args)
cute.go(args)
canvas = love.graphics.newCanvas(800, 600)
-- Rectangle is drawn to the canvas with the regular alpha blend mode.
love.graphics.setCanvas(canvas)
love.graphics.clear()
love.graphics.setBlendMode("alpha")
love.graphics.setColor(1, 0, 0, 0.5)
love.graphics.rectangle('fill', 0, 0, 100, 100)
love.graphics.setCanvas()
love.window.setMode(800, 800)
background = love.graphics.newImage("images/chess-board.png")
end
function love.update()
for i,p in ipairs(chessBoard.pieces) do
if p.type == 'pawn' and p.color == chessBoard.hasTurn then
p.justDidDoubleMove = false
end
end
hasTurn = chessBoard.hasTurn
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(background)
for i,piece in ipairs(chessBoard.pieces) do
piece:Draw()
end
love.graphics.setColor(255, 255, 255, 100)
love.graphics.rectangle("fill",chessBoard.shadowSquareX, chessBoard.shadowSquareY, 100,100)
end
function love.mousepressed(x,y)
print("-----------------------------------------------------------------------------------")
square = chessBoard:getSquare(x,y)
chessBoard:positionShadowSquare(square)
clickedPieceIndex = chessBoard:pieceInSquare(square)
print("Square: " .. square)
if clickedPieceIndex ~= nil then
clickedPiece = chessBoard.pieces[clickedPieceIndex]
clickedPiece.grabed = true
print("Possible moves " .. assert(inspect(clickedPiece:getPossibleMoves())))
print("Piece Id:" .. clickedPiece.id)
print("Has Moved:" .. tostring(clickedPiece.hasMoved))
print("Type:" .. clickedPiece.type)
print("Color:" .. clickedPiece.color)
print("Has turn:" .. chessBoard.hasTurn)
print("Just Did double:" .. tostring(clickedPiece.justDidDoubleMove))
print("Position:" .. assert(inspect(chessBoard:getPosition())))
print("FEN:" .. assert(inspect(chessBoard:posToFen())))
if clickedPiece.type == "pawn" then
print("Reached in Rome:" .. tostring(clickedPiece:inRome()))
end
end
end
function love.mousereleased(x,y)
local releaseSquare = chessBoard:getSquare(x,y)
if clickedPieceIndex ~= nil then
clickedPiece:moveTo(releaseSquare)
bot:findAttackedSquares()
end
clickedPieceIndex = nil
clickedPiece = nil
chessBoard:hideShadowSquare()
end
function love.keypressed(key)
if key == "v" or key == "V" then
print("evaluation :" .. bot:evaluatePosition(chessBoard.pieces))
end
end