ejnnr / chessboard Goto Github PK
View Code? Open in Web Editor NEWA php class to load FENs and PGNs.
A php class to load FENs and PGNs.
function loadFen should throw an exception if the kings of one or both colors are missing in the FEN. Otherwise errors could occur in other functions.
To read a PGN file, we need a function which converts move like "Nf3" in array("g1", "f3")
.
In this example it has to check for every knight on the board if it can reach f3. It should throw an exception if the move isn't clear (if there are to knights, which could move on f3). And of course it also has to understand moves like "Ngf3" or "N1f3" and "0-0", "0-0-0". It should remove + (check) at the end of a move.
We also need a function, which splits the PGN up into single moves and loads the meta data.
In its first move a pawn is able to move two squares forward. This has to be implemented in the isPossibleMove function.
There should be a function, which creates a PGN from the $moves list.
In the current isPossibleMove function a pawn can take pieces, which are in front of him.
At the moment the doMove function does absolutely nothing.
We need it for version 1.0.
Version 1.0 should have a function, which returns the FEN from the current position saved in $board.
In PGN files there can be variations in parantheses. Of course they need to be parsed seomhow, but they also need to be stored in $moves.
En passant and castling aren't supported yet by the isValidMove function.
(The isValidMove function does not have to be changed, we only need to change the isPossibleMove function).
Why is there a semicolon after the closing bracket in line 3?
The doMove function should also add the move to the $moves array.
isPossibleMove should do the check if there's a piece of the same color on the target square for all pieces together. Then it could also do the check for pieces of different colors together.
For managing PGNs, the class needs a variable, in which the complete game (all moves) is saved.
This could be an array like this:
array(
array("e2", "e4"),
array("c7", "c5"),
array("g1", "f3")
)
or like this:
array(
"e4",
"c5",
"Nf3"
)
I think the first one is much better, because the moves like "Nf3" must be converted only once, when loading the PGN file and not every time they shall be used.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.