Package: gym-togyzkumalak
Togyz Kumalak OpenAI GymTable of ContentsAbout GameRulesgym-togyzkumalakInstallationUsageEnvironmentObservationActionsRewardStarting StateEpisode TerminationResetRenderingExamplePlay random AgentsValid actionsUseful links and related worksLicenseAbout GameTogyz Kumalak (тоғыз құмалақ - Kazakh for “sheep droppings”), also known as Togyz Korgool (тогуз коргоол; same meaning) in Kyrgyz, is widely played in Central Asia. It is one of the few mancala games in which pits can be captured and turned into accumulation holes, a distinctive feature that adds another layer of strategic complexity. Togyz Kumalak has become a major mind sport that is officially promoted by the governments of Kazakhstan and Kyrgyztan.RulesThe game is played on a board, which consists of two rows of nine oblong holes (otau, literally, “yurt”) and two parallel furrows (kazan, literally, “kettle”) between them. The kazan serve as stores for captured balls. Initially, there are 9 little black balls (kumalak) in each hole. The holes are made in such a way that the two players can easily distinguish between an odd and an even number of balls. In addition, each player has a larger ball in a different color (usually white) that serves as a marker for any tuzduk the player might make later (see below). The players sit opposite each other, on the long sides of the board, directly in front of their holes. A player’s kazan, however, is adjacent to the opponent’s row. The player who starts the game is called “White”, the other player “Black”.
Picture
Togyz Kumalak starting position. White is light blue; Black is dark blue.
At his turn, a player takes with his index and middle finger all the balls of one of his holes, except one ball that is left in the hole, and distributes them, one by one, into the following holes in an anticlockwise direction around the board. If a hole contains only one ball, it is put into the next hole.If the last ball thus sown makes the contents of an opponent’s hole even, its contents are captured. They are shifted with the index and the middle finger into the player’s kazan. Note that the opening move of each game captures 10 balls except move 19 (see notation), which is for that reason a bad move.If the last ball falls into an opponent’s hole that has two balls (then numbering three balls), this hole is turned into a tuzduk (literally, “salty”) and marked with a special ball. During the game any balls, which fall into a tuzduk, are won by the player who owns the tuzduk, and are then transferred into this player’s kazan. A tuzduk is never skipped. Therefore, a tuzduk is an acquired accumulation hole, quite similar to the lubang rumah in Congkak or the kalah in the game of Kalah (usually known as “mancala” in the USA), except that in these games the accumulation holes are fixed from the beginning.There are some restrictions in regard to the tuzduk:Each player can create a tuzduk only once in a game. Players are permitted to make more moves that end in enemy holes containing two balls, but they will not turn them into tuzduk’s.
The ninth hole of the opponent cannot be turned into a tuzduk, only holes 1-8.
A hole becomes immune from being turned into a tuzduk, when the corresponding hole of the opponent has already become a tuzduk. For instance, if your opponent has created his tuzduk in YOUR second hole, you are no longer able to make a tuzduk in HIS second hole.The players move alternately and passing is prohibited. The game is finished when a player, on his turn, cannot make a move. In Kazakh this is called atsis kalu (literally, “left without a horse”). A player owns the balls he captured, the balls which fell into his tuzduk, and those that are still in his holes. The player with 82 balls or more wins. If both players have 81 balls, the game is a draw. In practical play, the game ends as soon as one player has secured the minimum number of balls needed to win, and the remaining moves are not played out.Game clocks are used in all important Togyz Kumalak tournaments. In world championships the thinking time is up to three hours for each player. In blitz tournaments, however, players may be given as little as seven minutes. When a player’s time has expired, the balls that have not been captured yet are awarded to his opponent.gym-togyzkumalakThis repository contains a Togyz Kumalak game implementation in OpenAI Gym.
Given the current state of the board, and the current player, it computes all the legal actions/moves (iteratively) that the current player can execute. The legal actions are generated in such a way that they can be moved in comparison with other actions that cannot be moved due to the fact that the holes may be empty or they are in a tuzduk state.InstallationInstall theOpenAI gym.Then install this package viagit clone https://github.com/zhasulan/gym-togyzkumalak.git
cd gym-togyzkumalak/
pip install -e .orpip install gym-togyzkumalakUsageimport gym
import gym_togyzkumalak

env = gym.make('Togyzkumalak-v0')EnvironmentThe encoding used to represent the state is inspired by the one used by Gerald Tesauro[1], although different due to the rules of the current game.ObservationType: Box(128)ComponentObservationMinMax0WHITE - 1st hole,  1st component0.01.01WHITE - 1st hole,  2nd component0.01.02WHITE - 1st hole,  3rd component0.01.03WHITE - 1st hole,  4th component0.01.04WHITE - 1st hole,  5th component0.01.05WHITE - 1st hole,  6th component0.018.06WHITE - 1st hole,  7th component0.01.07WHITE - 2nd hole,  1st component0.01.08WHITE - 2nd hole,  2nd component0.01.09WHITE - 2nd hole,  3rd component0.01.010WHITE - 2nd hole,  4th component0.01.011WHITE - 2nd hole,  5th component0.01.012WHITE - 2nd hole,  6th component0.018.013WHITE - 2nd hole,  7th component0.01.0...56WHITE - 9th hole,  1st component0.01.057WHITE - 9th hole,  2nd component0.01.058WHITE - 9th hole,  3rd component0.01.059WHITE - 9th hole,  4th component0.01.060WHITE - 9th hole,  5th component0.018.061WHITE - KAZAN hole balls0.01.062WHITE - Comparision kazans0.01.063BLACK - 1st hole,  1st component0.01.064BLACK - 1st hole,  2nd component0.01.065BLACK - 1st hole,  3rd component0.01.066BLACK - 1st hole,  4th component0.01.067BLACK - 1st hole,  5th component0.01.068BLACK - 1st hole,  6th component0.018.069BLACK - 1st hole,  7th component0.01.070BLACK - 2nd hole,  1st component0.01.071BLACK - 2nd hole,  2nd component0.01.072BLACK - 2nd hole,  3rd component0.01.073BLACK - 2nd hole,  4th component0.01.074BLACK - 2nd hole,  5th component0.01.075BLACK - 2nd hole,  6th component0.018.076BLACK - 2nd hole,  7th component0.01.0...119BLACK - 9th hole,  1st component0.01.0120BLACK - 9th hole,  2nd component0.01.0121BLACK - 9th hole,  3rd component0.01.0122BLACK - 9th hole,  4th component0.01.0123BLACK - 9th hole,  5th component0.018.0124BLACK - KAZAN hole balls0.01.0125BLACK - Comparision kazans0.01.0126-127Current player0.01.0Encoding of a single hole (from 1st to 8th holes):ComponentAlgorithm1stn >= 12ndn >= 23thn mod 24th(n mod 9) / 85th(n mod 18) / 176thn / 97thif hole is tuzduk9th hole algorithm is differentComponentAlgorithm1stn >= 12ndn mod 23th(n mod 9) / 84th(n mod 18) / 175thn / 9Example:BallsEncoding0[0.0, 0.0, 0.0, 0.0 / 8,  0.0 / 17, 0.0 / 9, 0.0]1[1.0, 0.0, 1.0, 1.0 / 8,  1.0 / 17, 1.0 / 9, 0.0]2[1.0, 1.0, 0.0, 2.0 / 8,  2.0 / 17, 2.0 / 9, 0.0]...9[1.0, 1.0, 1.0, 0.0 / 8,  9.0 / 17, 2.0 / 9, 0.0]10[1.0, 1.0, 0.0, 1.0 / 8, 10.0 / 17, 2.0 / 9, 0.0]...18[1.0, 1.0, 0.0, 0.0 / 8,  0.0 / 17, 2.0 / 9, 0.0]19[1.0, 1.0, 1.0, 1.0 / 8,  1.0 / 17, 2.0 / 9, 0.0]Encoding of KAZAN balls:BallsEncoding0 - 82 and more[ min(balls, 82) / 82 ]Encoding of comparision kazans (Example for WHITE player):BallsEncodingWK > BL[1.0]WK <= BL[0.0]WK = White kazanBK = Black kazanEncoding of the current player:PlayerEncodingWHITE[1.0, 0.0]BLACK[0.0, 1.0]ActionsRewardStarting StateEpisode TerminationResetRenderingExamplePlay Random AgentsValid actionsUseful links[1]Implementation Details TD-Gammonhttps://www.abstractgames.org/togyz-kumalak.htmlWikipediaLicenseMIT