Figuring computer players in Javascript

Carlos Pineda
2 min readApr 6, 2020

--

My most recent project was to create a software version of UNO, with a front end built with Javascript and React (Redux for state management). I had developed the gameplay logic to work with human players and the next step was to create 4 computer players to play the game so the game could be played without humans. Upon creating the computer player logic, it would proceed to break the game every time.

I started by checking the computer player logic to make sure that it was looking for the right attributes, then proceeded to the game play logic. While troubleshooting the gameplay logic, I realized some logic (+2, +4, wildcard) was handled by functions in my main component, but others (skip, reverse, next turn) was handled in a reducer (Redux) and changing the turn automatically. Therefore I standardized it by having the reducers just handle updating store and the gameplay actions and switching turns to be handled by functions. However, I was still running into the problem of a player playing out of order.

After researching online, asking fellow students, consulting with my coaches, and multiple failed attempts. I realized that designing the game to have 4 computer players was fundamentally flawed and I redesigned my game to have only one computer player as a “ghost” (not appearing on the screen) to make a decision for the appropriate player only during their turn, allowing the game to be played autonomously.

Here’s a demo video of my project: https://youtu.be/ir_LneMIcbU

Checkout the game at http://uno-y-medio.herokuapp.com

--

--