Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Chess A server-based web gaming application by Jordan Arnold.

Similar presentations


Presentation on theme: "Database Chess A server-based web gaming application by Jordan Arnold."— Presentation transcript:

1 Database Chess A server-based web gaming application by Jordan Arnold

2 Objectives To create a web-based game that can be played by two people across great distances Have a user interface for said game that is simple and intuitive, not requiring knowledge of web languages To do so using only languages and techniques learned in this course

3 Implementation I: Data Storage The information required to generate a chess game (the positions of all 32 pieces) is stored in a table on a MySql database. Positions are stored as integers, according to the grid shown, with the vertical as the 10's place and the horizontal as the 1's.

4 Implementation II: Interface The game board is displayed via a dynamically- created XHTML page, which is done in JavaScript. Each square on this grid is actually a transparent png image of a fixed size. Given the numbered positions of the pieces, this page displays corresponding images in the correct locations. Performing a move is done by simply clicking the desired piece and then its target square. Illegal moves are detected by the submission function, inside this code.

5 Implementation III: Data Retrieval The information stored on the MySql database is retrieved using a PHP file. Since the interface is done in Javascript, a method of sending information between the two was needed. The solution is to include the PHP code as an “external script”, as shown: This PHP file will dynamically create a Javascript code using “print()” statements. The interface page will then receive this script, which contains all the needed variable values

6 Implementation IV: Data Submission Updating the database requires sending data in the reverse direction, from Javascript to PHP. This is done using an XML HTTP Request. The relevant code is shown: xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","submitMove.php?piece=" + selectedPiece.id +"&moveTo=" + moveTo.id,true); The two variables, representing which piece was moved and where it was moved to, are added to the data stream after the file name. This information is retrieved in the PHP file via $_GET.

7 Game Rules The rules of the game are enforced by the client-side application, which will not allow an illegal move to be submitted to the server. This is done by checking the numbered indexes against the type of piece. For example, a Bishop can only move diagonally. The bishop is marked “B”, and its legal target squares are marked “T”. The Bishop is on square 74. All of its legal targets obey one of the following equations: (74 – T) % 9 == 0 or (74 – T) % 11 == 0

8 Game Rules II: In addition to the rules governing each specific piece, the following were also enforced: No piece may capture another piece of the same color. A blank square may not be selected first (it is impossible to move an empty square) No square may be selected twice (a piece may not “move” to its current square) Black pieces may not be moved on White's turn, and vice versa.

9 Future Improvements: While impressive, this game could benefit from several additional features, which I intend to implement in the future for my own benefit. These include: More complicated rules of Chess (castling, En Passant, promotions, etc.) Chat feature to allow opponents to communicate. User-accessible record of the game in chess notation.


Download ppt "Database Chess A server-based web gaming application by Jordan Arnold."

Similar presentations


Ads by Google