Imgur album containing screenshots of code functionality: https://imgur.com/a/qu9VeOI
Settlers of Catan is a board game where players build settlements on the intersections of resource tiles. Each tile is associated with a numeric value and on each players turn, the dice are rolled and resources are gathered if a settlement or city that a player controls is adjacent to a resource tile with that numeric value. Players can trade resources and spend them to build new settlements and roads, purchase cards which include events and knights, and upgrade settlements to cities. A player wins by collecting a certain number of victory points which are awarded for building infrastructure including the longest connected road, and the largest army represented by knight cards which are collected and held. There are several tedious tasks associated with playing Settlers of Catan including keeping track of victory points and counting resources that are collected each turn. For this project, a camera is suspended above a game board for Settlers of Catan. At the beginning of the game, the board is initialized with no pieces in order to store the location, resource, and number associated with each tile as they do not move or change throughout the course of the game. Each turn, the board and dice will be analyzed. Resources that each player gathered are displayed based on the dice roll and the positions of their settlements and cities. In addition, the victory points each player represents on the board will be displayed. The robber piece is also tracked because resource tiles occupied by the robber do not yield resources. Resource, event, and knight cards held in hand are not tracked. While many of these objectives have been met, this project should be considered a work in progress. This project was built on Linux and compiled using cmake. It is untested on Windows or Macintosh OS. OpenCV libraries including OpenCV_contrib are required.
This project has several requirements in camera setup, lighting, and game play flow for proper functionality. The project assumes that the camera will not move with respect to the board throughout the course of the game. As a result, a custom wooden structure was constructed which includes a mount for a webcam placed directly over the center of the game board positioned to create an approximately orthonormal image. The entire game board as well as enough space on either side of the board for the largest army and longest road cards should be in frame. The camera must be at least 1080p in resolution in order to detect enough detail for SURF and ArUco functionality. The wooden structure also has pegs which hold the game board in place to prevent it from moving throughout the course of the game. Direct lighting which causes glare should be minimized as much as possible. The project works best when the game board is illuminated by soft, natural, bright, white lighting such as sunlight coming in through multiple, large windows. The project does not have the functionality to identify the arabic numbers which represent the numbers associated with each resource tile. The camera used is also not high enough resolution to consistently detect the dots on the default dice of the game. As a result, ArUco tags are taped to the bottoms of the number tiles as well as the sides of the dice. The ArUco tags should be at least 2 cm length and width and should be from the original ArUco dictionary. The ArUco tags 0-6 should be used for the dice and the tags 36-41 and 43-47 should be used for the tile pieces. 42 is skipped because there is no tile piece for a dice roll of 7. The Aruco tags for the tiles should be such that the ArUco tag id should be the number value of the tile plus 34. There are four colored player pieces in the base game of Settlers of Catan. They are red, blue, white and orange. Because of the similarity of the orange pieces to the color of the brick resource tiles and the similarity in color of the white pieces to the boarders of the hexagon tiles where the pieces sit, the project is limited to only two player colors: red and blue.
Detection of the dice roll without ArUco tags proved difficult due to the small size of the dots inside the dice and the fact that multiple sides of the dice may be visible in frame at any given time. A higher resolution camera would help making default dice detection possible using contour finding. Automatic longest road detection is possible because the project already detects roads and implementation would be a matter of using an algorithm that can find connected roads based on their locations. Another feature that is possible is detecting the default Arabic number tiles. When the team tried to implement this feature, Hough circles was used to detect the tiles and template matching was used to identify the numbers. It was found that it is difficult to use Hough circle detection to detect the circles without a large number of false detections. It was also found that the template matching returned low sum of squared difference scores because of the tilt of the number tiles caused by human error. The combination of these factors made it difficult to distinguish between false detections and slightly tilted numbers. One approach that might yeild better results would be to use Tesseract OCR, an open source project made by Google which is designed for language recognition.