TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
http://www.roblox.com/games/141589686/Chess
prntscr.com/9pp9qy
Trying to finish my extremely inefficient gui chess game I started more than a year ago. I have been away for college but I have new motivation to complete the game I have all the piece movement and now am trying to figure out how to make sure that the game checks if squares are being attacked by pieces and checks if pieces are blocking the paths, and if moving pieces will put the king in check.
To-Do:
En Passant
index pieces on each square
index attacking piece threats of each square
index potential threats (if a blocking piece moved out of the way, the square would be marked as attacked)
check if king is in check
check if king will be in check (if a blocking piece moves out of the way)
check if 3-fold repetion
check 50-move draw
check stalemate
check for checkmate(king can't move+attacked)
Promoting Pieces
Insufficient material
Loss on time
functionality for black side
Background:
I gave each square a number to help in the movement of pieces. I numbered each square from 0-63. a1 = 0 and h8 = 63
En passant:
send the server that black moved a black pawn 2 squares in a single move and send the server the square the black pawn landed on. Loop through all the white pieces and check if there is a white pawn on any square from a5-h5. If true, check if the square the black pawn landed on is adjacent from the white pawn, i.e if the white pawn is on square b5(12) then an adjacent square = a5(4) or c5(20) which then means if the square is -8 or +8 or the white square. If true, then tell the client that he can capture via en passant. If he does not, en passant will be set as false.
indexing pieces on each square:
When the board initializes, each piece will have their own corresponding XY Position via Scale and also the Square and Square number. When a piece moves the server will loop through all the squares and add a StringValue with the pieces name. This will essentially help in checking if the movement of a piece is blocked; hence (blocking piece).
Index attacking piece threats on each square:
After piece moves, the server will use the piece attacking rules and mark corresponding squares attacked. For example if you move a white pawn to e4(35) then the attacked/threatened squares will be d5(28) and f5(44). Another example if you move a queen to e4 then if you understand the movement of a queen, it will be able to attack vertically, horizontally, and diagonally from that position. Then the server will loop through all the squares and check if there is a piece situated on that square. If there is a piece, the loop will end and continue for the other directions. (This is what i see one of my most difficult things to code)
Potential threats (pinning pieces):
I came up with this solution to help check if the king would be put in check if one moves a blocking piece out of the way. After the server indexes the attacked squares, if it finds a blocking piece, the squares that would be attacked (if there wasn't a blocking piece) are marked as potential threats. This will prevent players from moving their pieces and placing their king in check. (In chess this is what we call pinning a piece)
King Checks:
When a piece moves and the server indexes the attacked squares, the server will then check if the king is on an attacked square. If true, then it will flag the client as "inCheck". The player must then either move a piece in the way or move the king. This will then tell the server to index potential threats.
Will king be in check:
Basically I can just combine or already have this code in the potential threats
3-fold repetition:
If the players move the same piece 3 times in a row then server will flag as a draw, ending the game.
50-move:
A counter will be added for every move a player makes that isn't a pawn. The counter will be reset if a player moves a pawn. If 50 move count is hit for both players, then the game will be drawn.
check stalemate:
Server will check if there are no remaining squares to move the king because the squares are marked as attacked. If true then the game will be called a stalemate, essentially a draw.
Checkmate:
Server will check if king cannot move and is on an attacking square
Promotion:
After a player moves, if the square the pawn landed on is a8-h8 then a dialog will appear listing options of pieces for the player to select. The pawn gui will be changed into the selected piece and will be indexed into the game.
Insufficient material:
Server will check if there isn't enough material to checkmate
Loss on time: if a player loses on time first, the other will be declared the winner
In summary: These all of what i have planned to implement. I have not been able to find any more efficient ways to handle the game. If you have any tips,tricks,smart math calculations towards simplifying this I would be extremely thankful. I believe chess is a community project for all ages. I want to promote chess on roblox in the premise that chess is very educational. I also believe that chess brings on very intellectual discussion of all ages. I hope those of you here might appreciate my project and support the completion to it. THANK YOU! ~TimeTicks |
|
|
Some things I'd do:
- Make a function that can take coordinates and give you a square
- Make a function that takes a square and gives coordinates
- Make functions that can get you all squares in a row, column, or diagonal line (that'll let you easily access which squares are available to rooks, bishops, and queens)
- Inside of each square include values for coordinates, color, and which piece is on it
- Make functions that will tell you if two coordinates are...
---- Horizontally aligned
---- Vertically aligned
---- Diagonally aligned
---- Adjacent to each other
---- In an L formation (can a knight move between them?)
Put all of these in a ModuleScript so the entire game has access to them. Take it in small steps, do one after the other. Include or exclude whichever ones you want. Remember: it's a board game, it's played on a board. The squares pretty much make up the entire game. Describing chess games by the squares is the standard, that's how important they are. |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
I agree. I've taken my game to a deep dark abyss beyond no return. I have looked over many source codes of chess games, all of which do exactly what you described. Thanks for the feedback! Functions make everything easier. |
|
|
No problem :D
Functions are super awesome! |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Finished indexing blocking pieces.
Implemented black piece movement.
http://prntscr.com/9r041l
I'm looking forward to finishing this game. It is progressing along nicely. I'm going to start implementing capturing pieces which will lead me into indexing attacked squares by pieces! :D |
|
lupineJoin Date: 2008-06-24 Post Count: 3561 |
When I made my chess game, I did the following
1. Set up a table and stored 'Piece' objects in it. The objects simply looked like,
{Name = "Bishop", Team = "White", Type = 3}
2. With each of these objects, I set up a method,
function piece:GetTiles()
Which returned all the tiles a piece could move to, either to just move or take another piece.
3. That was pretty much it. I stored the game in a 2d array, so it looked something like
(Ki = 1, Q = 2, B = 3, Kn = 4, R = 5, P = 6)
{{5 4 3 1 2 3 4 5},
{6 6 6 6 6 6 6 6},
{0 0 0 0 0 0 0 0},
{0 0 0 0 0 0 0 0},
{0 0 0 0 0 0 0 0},
{0 0 0 0 0 0 0 0},
{6 6 6 6 6 6 6 6},
{5 4 3 1 2 3 4 5}
}
^ bear in mind, all those numbers should have commas between them. Halfway through typing it I realized I forgot and I'm too lazy to fix it.
As you go down, 'Y' increases
As you go right, 'X' increases
To check all valid movements for, lets say, a rook, you would cycle through 'X'. If the tile has a value 0, add it to the list. If it's a non-0 and it's an ally piece, break loop. If it's a non-0 and an enemy piece, add it and break loop. Then do the same for Y
To check all valid movements for, lets say, a bishop, you would cycle through 'X' and 'Y' at the same time, either as (X, Y), (-X, Y), (X, -Y), or (-X, -Y) and do the same logic to add tiles as prior.
For En Passants, I simply coded an event that every time a pawn moved 2 spaces and there was another enemy pawn in either X adjacent square, add the tile behind (so either row 2 or 7) to the list of valid moves for the adjacent pawn.
Hope this helped; good luck! PM me if you need any more logical help. I made a chess game for my CS class a couple semesters ago, so I got this. :P |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Game now supports 2 player piece movement. There are no captures implemented atm but at least you can see each others moves! |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
After getting free time from college I started working on capturing pieces and went through plenty of debugging to finally get the movement correct. There might still be some bugs, please report them to me. Watch the video for some peaks into my game
www.youtube.com/watch?v=wiLXJB5GfHg |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
After working long hours on the game and trying to do this and school at the same time, I finally was able to implement more features that were desperately needed:
Loss on time
Loss from leaving the game
Resignation
Promoting a pawn
En passant
Heres a peek at the promotion dialog:
prntscr.com/9y4lmm
prntscr.com/9y4lpj
|
|
|
"To-Do:
En Passant"
NOOOO! My favorite move D:
I do it and everyone thinks I'm cheating. |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
ahaha the struggle |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Implemented the 50 move rule. I forgot to mention that I did add some subtle chess sounds for moves and game creation/game ending |
|
DarkenusJoin Date: 2014-07-17 Post Count: 1997 |
I remember when you showed us this project like in 2015...... oh the good days... |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Finally added option to change the game time and increment.
Also added Tweening to the pieces for smoother movement. Will add customization options to the animation speed of the pieces.
http://prntscr.com/a0cxot |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
After a couple of weeks I have finally managed to implement checks into the game. my next goal is to check for stalemates and checkmates. After that you have a fully functional game!!!
http://prntscr.com/a8hnbo
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
I've been testing some new themes. How do you like them? What themes would you like to have?
Fritz Maple
http://prntscr.com/a8mnvg
Dark Cherry
http://prntscr.com/a8mp3k
Mahogany
http://prntscr.com/a8mpr5
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
I've been very lazy but I finally implemented rematches and draws in the game. Lol
|
|