[FMP Tip-n-Trick] FileMaker Developer Busts Through Stalemate to Create Chess Engine
FileMaker Database App Reigns in Gaming Platform
by Joe Cellino, eXcelisys FileMaker Developer
There are two things that bring me joy in this world — chess and FileMaker. I never thought that these two passions would cross paths in my lifetime, but now, that day has come.
Having spent the past several years immersed in the tech industry, I’ve seen how rapidly machine learning has progressed. From autonomous self-driving vehicles to Google Assistant, which carries on conversations eerily similar to those held by humans, America’s technological landscape is constantly evolving.
While all of this technology is impressive, my favorite “deep learning” champ has to be AlphaGo Zero. AlphaGo is a machine learning program. Give AlphaGo a set of rules for a game and it will play itself repetitively until it masters the game. In other words, AlphaGo learns by playing itself, improving with each game.
In late 2017, AlphaGo was given four hours to “self-train” and learn the game of chess. AlphaGo then played the world’s best computer chess engine, Stockfish. Stockfish has dominated the chess world for years, consistently winning the World’s Chess Engine Championship. But in this matchup, Stockfish performed like a fish out of water. Of the 100 games played, AlphaGo won a triumphant 28 and played to a draw on the rest (find match details here).
Inspired by AlphaGo Zero, I wondered if it would be possible to create a chess engine on the FileMaker Platform. In the five years I’ve been developing with FileMaker, I had never considered using the platform to design games.
I developed a plan of attack:
- Create the data structure
- Set up a board and get the pieces to move
- Develop piece movement logic
- Add more rules like castling, en passant and check
- Add checkmate and stalemate
The start of a game. The FileMaker Go Zero chess app utilizes button bars, container calculations and custom scripts and functions to process each move.
The data structure was easy. Each game can have many moves. Done. Setting up the board was a little more difficult. Initially, I thought I could utilize the drag-and-drop feature of container fields to move pieces and control the game through script triggers. For example, when clicking into a container the OnObjectEnter script trigger would determine what square had been selected. When the image was drag-dropped into another container, the OnObjectModify script trigger would process the move. This seemed to cause more problems than it was worth because the script triggers wouldn’t always run and when they didn’t, the entire game was ruined. To fix this problem, I decided to use button bars instead due to their stability in running scripts.
I also made a decision to store each piece image in a “pieces table” instead of storing each one directly on the board. This made it possible to display a piece’s image using container calculations that were driven by text fields that stored a carriage-return list of the squares occupied by each piece.
After the board was set up and the pieces had the ability to move, the next step involved developing the logic for each piece’s movement. I was able to create each piece’s movement logic using scripts and custom functions to determine if squares were occupied and/or available. The scripting works as follows:
- The player selects a square.
- Based on the image in the square, determine the square, piece and color.
- If a piece is selected and it is that color’s turn, then determine all of the legal squares that type of piece can move to.
- If the player selects one of the legal squares, then move the piece by modifying the appropriate text field that stores the piece’s placement. If the player selects a different square, run steps 2 thru 4 again.
White puts black in check. Notice that the app catalogs each move as it is made.
Castling and en passant were easily handled with additional scripting and logic, but dealing with kings in check proved more complicated. I began by creating a script that calculates all of the squares the opposing color’s pieces are attacking (i.e. protected squares). This script runs after each move. I set it up so the king could not legally be moved to a protected square and if your king is in a protected square at the start of your turn, you are in check.
At first, I thought this was enough but soon realized that you can move other pieces besides the king to end up in check. I therefore had to “check for check” when determining legal moves for every piece. It is important that you determine check after any piece is moved because a piece can be shielding your king from an opponent’s piece and, if moved, will place you in check. This requires a lot more processing power because checking for check requires determining the protected squares after the piece is hypothetically moved.
Checkmate and stalemate require looking one move ahead. If it is your turn and you are in check and you have no legal moves, then it is checkmate. If you remove check from the first scenario, then it is stalemate. Both of these seem to go hand in hand with creating an AI that can make intelligent legal moves, so I decided to leave these features out of this version.
Get a piece of the action. Download the FileMaker Go Zero chess engine today.
In the future my goal is to add computer AI that would be able to determine its legal moves and make an intelligent choice aimed at winning the game. It seems as if I have the right scripting structure to be able to determine legal moves. I would theoretically have to link moves through a child / parent relationship and build a tree data structure in order to see moves ahead and determine if the future positions are good or bad. Then maybe one day my engine could compete against the AlphaGo chess playing software in the computer world chess championships. Stay tuned for my next version.
If you’re stuck in a database checkmate and need a FileMaker developer to attack the problem, contact eXcelisys today for a complimentary consultation.
______________________________________________________________________________________________
**This article is provided for free and as-is, use, enjoy, learn, and experiment at your own risk – but have fun! eXcelisys does not offer any free support or free assistance with any of the contents of this blog post. If you would like help or assistance, please consider retaining eXcelisys’ FileMaker Pro consulting & development services.
About eXcelisys, Inc.: Founded in 2001, eXcelisys (www.excelisys.com)is an FBA Platinum Partner and FileMaker Certified developer organization. eXcelisys specializes in designing, developing, customizing, supporting, consulting, migrating, upgrading, fixing, and integrating of database solutions for Desktop, Mobile, and Web applications. Our core technology competencies are FileMaker Pro, FileMaker Go, and MySQL for database frameworks, along with FileMaker WebDirect, WordPress, MySQL, PHP, CodeIgniter, PostgreSQL, Joomla, Drupal, Magento, CSS, HTML5, and Javascript for web sites and web applications. Aside from providing eXcellent customer service, our goals are to use these technologies to intuitively automate your organization’s data solution needs seamlessly and flawlessly across the web, mobile, and desktop platforms. Contact eXcelisys today for a free estimate and consultation about making your business more efficient through intuitive and effective software automation. 866-592-9235.
eXcelisys, Inc. is an independent entity and this website/information/blog post has not been authorized, sponsored, or otherwise affiliated with FileMaker, Inc. FileMaker is a trademark of FileMaker, Inc., registered in the U.S. and other countries.
Great article. The game looks awesome! Thanks for sharing the source code.
Very interesting. I wish I could reach that level of programming. How about one for bus, airplane, stadium sitting that does not involve Execute SQL programming. I need to ask the price for the development of a project, can I get an email?
Thanks for the code to the chess game, and will look forward to the AI version! I don’t think that FM was ever envisioned as a gaming development platform, but I have found that it actually works quite well for board-type games. I’ve developed a few myself, over the years, just for the heck of it and for the challenge. Designing and building games on FM is about as much of a thrill as the games themselves! Thanks for sharing.
Fantastic article and demo file – how creative! Chess and FileMaker what is not to love! Thanks for sharing
Very well done! A chess game in Filemaker. I wish I could program like that. I found this page because I intended to use Filemaker to create a database of chess positions (FEN) with the ability to add an evaluation to each position including my repertoire moves. To send a FEN-file to Filemaker and have Filemaker present the position on a board was the biggest challenge. You showed me that it is possible! Thank you.
Joe Cellino’s inventive fusion of chess and FileMaker not only showcases a remarkable technical achievement but also highlights his passion and dedication to both fields. By venturing beyond the traditional boundaries of database development to create a chess engine within FileMaker, Cellino has exemplified innovative thinking and problem-solving skills. This work not only enriches the FileMaker community by pushing the limits of what can be achieved with the platform but also serves as an inspiration to developers and enthusiasts alike, proving that with creativity and expertise, even the most unconventional ideas can be brought to life. His clear exposition of the challenges faced and the solutions devised offers a valuable learning resource for others interested in exploring the intersection of gaming and software development. Kudos to Joe Cellino for blending his love for chess with his professional expertise in FileMaker, resulting in a compelling demonstration of how hobbies and work can intersect to create something truly unique and engaging.