You are on page 1of 6

Dismath: Discrete Math Gamified Educational Tool

in Logic with Minimax Algorithm and Pruning


Melvin Cabatuan
De La Salle University
Manila, Philippines
melvin.cabatuan@dlsu.edu.ph

Abstract—This paper presents the design and development movements are inspired by the “Dama” game, a Filipino
of Dismath, a gamified educational tool for propositional logic variant of international checkers [8]. Dama board game is
introduction to undergraduate computer engineering students. similar to international draught where a single chip can jump
Additionally, an artificial intelligence (AI) agent is developed for in both forward and backward diagonal direction and the King
the proposed Dismath game based on minimax tree search with (or Dama) can move or jump at any distance along a diagonal
alpha-beta pruning (MMAB). Dismath is an international similar to a bishop’s movement in a Chess game but jumping
checker variant inspired by Damath game in which operations over the taken piece. A unique addition of Damath game is the
are defined in every checkerboard positions. Thus, the final usage of basic arithmetic operations in the board (Fig. 1) and
score is not only dependent on the pieces left but also in the
the assignment of values to the checkers (chips) [9], in which
operation results. In a capture move, the jumping chip is the
the jump scoring is based, with the jumping chip as the first
first operand, the captured piece acts as the second operand, and
the operation defined in the destination block where the chip operand, the captured piece as the second operand, and
landed after the jump is utilized for the binary operation. utilizing the operation in the destination block where the chip
Instead of arithmetic operators, Dismath designates logical landed after the jump. Damath, as a form of activity-based
connectives on the checkerboard. All white and black pieces learning/teaching, has been shown to improve students’
were assigned true and false truth values. For scoring, a true (T) conceptual understanding, perception and procedural skills in
and a false (F) truth values are calculated as +1 and -1, while a integers [10].
dama or king chip is valued +2 and -2 for White and Black
In this paper, we present a Dismath (Discrete Math) board
pieces, respectively. If the game ends with a positive value, then
white wins; otherwise black wins, unless the score is zero in
game for a gamified introduction to logic in engineering
which the outcome is draw. Board balancing experiments were education inspired by Damath. Propositional logic is among
conducted using the win-win ratio between the two random the topics covered in a Discrete Mathematics course
players as evaluation metric. Furthermore, the MMAB agent fundamental to computing and computer engineering.
was characterized against a random player baseline. The results However, most beginner students find difficulty in
showed dominant performance of MMAB AI agent in proposed manipulating the set of symbols and logic operations
Dismath game losing only at depth equal to 1. Overall, this result involved. Thus, the main goal of Dismath is to promote
is promising on its own demonstrating the automated gameplay familiarization, conceptual understanding, and procedural
of the proposed Dismath educational tool for logic introduction. skills in classical propositional logic. Additionally, the process
of game development will also introduce basic operations in
Keywords—gamification, propositional logic, board games, computing, i.e. integer division and modulo operation for
damath, minimax algorithm, alpha-beta pruning, evolutionary game board indexing/location notation. A metric for board
balancing is also introduced using the win-win ratio of random
I. INTRODUCTION players playing against each other. Furthermore, the board
The analysis of games have regularly been pushing balancing metric was utilized as a fitness function for an
boundaries of what can be achieved with computing and evolutionary strategy used for automatic generation of
artificial intelligence. For instance, the game of checkers, with operation arrangements in the board. Finally, an artificial
high decision complexity having approximately 500 billion intelligence (AI) agent is developed for Dismath board game
billion (5 × 1020) possible positions, was solved by Schaeffer utilizing minimax tree search algorithm with alpha-beta
and his team [1] after working on the problem for about 19 pruning.
years. The result for checkers was concluded to be a draw
assuming perfect play by both sides. Another popular board This paper is organized as follows – the methodology is
games with high decision complexities are Chess and Go. discussed in section II, followed by the results and discussions
Although these games are not yet perfectly solved as in in section III. Finally, this paper is concluded in section IV.
checkers, superhuman performance AI agents have been
developed that can beat human grand champions in these
games – AlphaGo[2] and AlphaZero[3].
Gamification in learning can improve learning outcomes
by enhancing engagement and increasing activation of
working memory [4]. In this regard, a board game approach to
knowledge acquisition provides promising results [5]. Board
games has also been used as a learning tool for acquiring
computer programming language, e.g. Python [6]. In the
Philippines, “Damath” board game is being promoted by the
Department of Education (DepEd) as a tool for learning basic
mathematics and is popular in local school competitions [7].
In Damath, the 8×8 checkerboard and 12 playable pieces or
chips for each players together with their corresponding
Fig. 1. Standard Damath board with basic arithmetic operations.

XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE


II. METHODOLOGY The overall game score is a function of pieces, white (ω)
and black (β), left in the board and the capture scores (s), as
A. Game Design depicted in (2). If the player makes a capture, the ‘jumping’
Dismath as a board game inherits some important chip is set as the first operand, the captured piece as the second
characteristics for learning which is considered during the operand, and the operation in the destination block where the
planning stages, namely [11]: ‘jumping’ chip landed is utilized, e.g. (a) White capture, T ∨
1. Immersive and playful feature of board games F ≡ T, valued as +1; (b) Black capture, F ∨ T ≡ T, valued
promotes attention, concentration and as +1. Although the previous jump examples have the same
motivation of players; capture values, the result is different, e.g. in (a) the capture
score is +1, and the Black pieces left is decreased by one piece,
2. In a game environment, players experience a thus, the overall score for the move in (a) is +2, in White
“suspension of disbelief” that facilitates player’s favor. In (b), even if the jump reduces the White
acceptance of ideas even far from their everyday pieces with -1, the capture score is making up for that with an
experience; additional +1, thus, the net result of the move to the overall
3. Board games permits a “learn by doing” score is zero. The overall scoring is described in Table I.
approach that helps the students hone particular
TABLE I. DISMATH GAME SCORING FOR ORDINARY CHIP
skills, build relationships and experience;
Game Scoring (White, ω ≡T; Black, β ≡ F)
4. The competitive nature of board games and the Logical
Operation Capture Logic Capture Chip Final
natural will to win of players encourage deep Expression Result Point Loss/Gain Score
understanding of the rules behind the game; ω∨β T +1 +1 +2
Disjunction -1 0
β∨ω T +1
5. The gameplay interlude, i.e. waiting for the
Alternative ω↑β T +1 +1 +2
opponent's moves, stimulates reflections and Denial β↑ω T +1 -1 0
discussions among players; Exclusive ω ⊻ β T +1 +1 +2
6. Immediate feedback occurs during gameplay Disjunction β ⊻ ω T +1 -1 0
ω∧β F -1 +1 0
instead of waiting for hours or even days if Conjunction -1 -2
β∧ω F -1
consulted to the instructor;
ω↓β F -1 +1 0
Joint Denial -1 -2
7. The gameplay enables strategic thinking skills β↓ω F -1
and cognitive action performance, i.e. ω⇔β F -1 +1 0
Biconditional
remembering the game rules, keeping aware of β⇔ω F -1 -1 -2
Converse ω⇐β T +1 +1 2
bad moves, and recalling the sequence of play; Implication β⇐ω F -1 -1 -2
8. Board games promote collaboration in which ¬ω,a F -1 +1 0
Negation
¬β,a T +1 -1 0
students are able to help one another with both
a.
drill-and-practice types of learning and The second operand or the taken piece is removed but not used in the unary ¬ operation.

additional conceptual based undertakings.


When the player chip reaches any block in the row
Dismath, as a variant of checkers, is a zero-sum game by closest to the opponent side and stays there after the move
design or whatever is won by a player is lost by its opponent. (not continuing a capture), the piece becomes a dama or
Initially, each player starts with 12 chips with a corresponding
king. The dama chip is valued ωk = +2 and βk = -2 for
truth value – T (true) for White and F (false) for Black chips,
respectively. Numerically, a true value and a false value is White and Black pieces, respectively. As in international
calculated as ωi = +1 and βi = -1, respectively. Thus, the initial checkers, the dama can move in all diagonal directions
configuration of Dismath is zero considering the total value of and at any distance along a diagonal as long as it is vacant,
chips. The objective of the White player is to gain true values
TABLE II. DISMATH GAME SCORING FOR DAMA (KING) CHIP
or positives points, contrarily, the Black player’s goal is to get
false values or negative points. If the game ends with positive Game Scoring (White, ω ≡T; Black, β ≡ F)
Logical
score, White wins; else if the final score is negative, Black Operation Capture Logic Capture Chip Final
wins; otherwise, when the overall score is zero, the outcome Expression Result Point Loss/Gain Score
is a draw, as in (1). ω∨β T +1 +1 +2
Disjunction -1 0
β∨ω T +1
Alternative ω↑β T +1 +1 +2
Denial ¬β ↑ ω F -1 -1 -2
(1) Exclusive ω ⊻ β +1 +1 +2
T
Disjunction ¬β ⊻ ω F -1 -1 -2
ω∧β F -1 +1 0
Conjunction -1 -2
β∧ω F -1
¬ω ↓ β T +1 +1 +2
where: Joint Denial -1 -2
β↓ω F -1
¬ω ⇔ β T +1 +1 +2
Biconditional
β⇔ω F -1 -1 -2
(2) Converse ω⇐β T +1 +1 2
Implication β⇐ω F -1 -1 -2
¬¬ ω , a T +1 +1 2
Negation
¬¬ β , a F -1 -1 -2
b.
The second operand or the taken piece is removed but not used in the unary ¬ operation.
but in Dismath, the dama is forbidden to capture a piece at a the gene set, G = {∧,∨,↑,↓,⇐,¬,⇔,⊻}, then, the best parent
long distance diagonal, that is, like a normal chip, the dama for each generation is acquired using equation (3)
needs the piece to be next to it, in order to make a jump. An win/win ratio as the fitness. The best parent is mutated
additional capability of a dama is the ability to negate its truth every after each generation by changing one element of the
value, thus, capture/jump results for Alternative Denial, best parent at random. This process is repeated for many
Exclusive Disjunction, Joint Denial, and Negation will change generations until an acceptable fitness is achieved.
depending on the preference of the player (optional). The
dama jump scoring along with the final score are presented in C. Evaluation Metric for Balancing
detail in Table II, assuming that the player will utilize the Since the game design is targeting beginner students,
dama’s negation capability efficiently. random play is assumed for board configuration. Thus, given
a certain number of games, m, played between two random
players, the evaluation is decided using the win-win ratio
between the two, as in (3), where WW stands for the number
of White wins an BW for Black wins.
(3)

D. Dismath Game Mechanics Summary


The general Dismath game rules can be enumerated as
follows:
1. A coin toss decides the player to make the first
move – either White or Black player. Then, they
alternate turns, a pass is not allowed.
2. Each player has initial 12 chips with a
corresponding truth value – T (true) for White
Fig. 2. Standard Dismath board without the logical operations. Note: The and F (false) for Black chips, respectively.
first move for both players have been completed, thus, it can be recorded as
<move number> <white_start>-<white_stop> <black_start>-<black_stop> 3. Touch-move rule. If a player touches a chip on
<overall_cumulative_score>, e.g. 1) 17-24 44-37 0. The GUI is written his turn, it should be moved unless there is no
using Python/Pygame. legal move possible.
B. Dismath Board Design and Notation 4. Each player shall record their moves (including
For simplicity, the Dismath game board notation follows the opponent) along with the cumulative score
an n = 64 one dimensional indexing (Fig. 2) as opposed to n = using the standard n64 notation, as in Fig. 2:
32 standard checker indexing in [1]. Thus, when white chip <move number> <white_start>-<white_stop> <black_start>-
moves forward to the left, the index can be updated as index <black_stop> <move_score>,
plus 7, e.g. 17-24, similarly, a move forward to the right is e.g. 1) 17-24 44-37 0.
updated as index plus 9, e.g. 17-26. If the black chip is moving
forward to the left, the index can be updated as index minus 9, 5. Each player is only allowed 1 minute to move
e.g. 46-37, similarly, if it moves forward to the right, the index including the recording of the move and score.
can be updated as, index minus 7, e.g. 44-37, respectively. 6. All moves for ordinary pieces should consist of
Half of the indices are not utilized since the Dismath game forward movement only (in a single adjacent
only uses the light squares where the operations can be diagonal) except when capturing or jumping over
written. It is also important to note that rows and columns of an opponent’s chip in which both forward and
the board can be easily accessed using the integer division and backward jump is allowed.
modulo operations applied to the index.
7. When the ordinary chip reaches the row closest
The board operation configuration is subject to to the opponent, e.g. positions 56, 58, 60, and 62
experimentation since balancing is a significant issue for the White player, it becomes a dama or king.
considered in the game design. For this reason, logical A dama chip can slide diagonally (single or
implication was not included and replaced with its converse. multiple squares as long as it is unobstructed) in
For ordinary pieces, implication does not pose an issue since both forward and backward directions. However,
both white and black capture will end up in zero net score as in Dismath, a dama chip captures/jumps only on
the taken piece value is accounted for, but the imbalance adjacent opponent chips similar to an ordinary
occurs when the chip is dama utilizing the negation power, a jump. A player with dama chip has the option to
white king can negate itself as it takes a black chip, thus, negate its own value during jumps by declaration.
getting the positive desired value. Unfortunately, the black
king cannot benefit from the negation power since even if it 8. For scoring, a true and a false truth values are
negates itself, the result is still true, favoring the white player. calculated as ωi = +1 and βi = -1, while a dama
Multiple board operation configurations will be evaluated for chip is valued ωk = +2 and βk = -2 for White and
balancing which includes, (a) horizontal, (b) vertical, (c) Black pieces, respectively. In a capture move, the
diagonal-symmetric, (d) damath-style board, and (e) jumping chip is the first operand, the captured
evolutionary strategy (ES) based configuration. The piece acts as the second operand, and the
evolutionary-based strategy utilizes the logical connectives as operation in the destination block where the chip
landed after the jump is utilized for the binary
operation (Tables I and II). Note: Forced capture A. Board Operations/Connectives Configuration
rule is enforced, in which, a player must make the As stated in the methodology section, the explored board
jump if it is available, including multiple jumps. configuration includes, (a) horizontal, Fig. 3, (b) vertical, Fig.
9. The overall score in a move is computed as a total 4, (c) diagonally-symmetric, Fig. 6, (d) damath-style board,
of pieces left and the capture or jump score for Fig. 7, and (e) evolutionary strategy (ES) based configuration,
the move. The pieces left valuation is stated in Fig. 5.
(3.) while the capture scores are presented in
Tables I and II, for ordinary and dama chips.
10. The game ends on the following terms:
a. Any player has no moves (or cornered).
b. Any player has no more pieces left.
c. Threefold repetition rule. A player may
declare a game termination if the same
position occurs three times.
d. The 30-minute overall game time limit
has lapsed.
Once the game ends, the outcome is decided
using equation (1), that is, if the final
cumulative score is positive, then the White
player wins, if the final cumulative score is
negative, then the Black player wins, Fig. 3. Horizontally-symmetric (HSB) Dismath board
otherwise, the game outcome is a draw.
E. Minimax with Alpha-Beta Pruning

A1. MMAB: Minimax with Alpha-Beta Pruning Algorithm


Input: depth, player_side, alpha, beta
Output: best score associated with a node
1. if (depth = 0) then // terminal or leaf node
2. return static_evaluation(player_side, chips_list, jump_scores)
3. end if
4. nodes ← get_all_possible_single_moves(player_side, chips_list)
5. if (player_side = BLACK) then // Minimizing Player
6. for each child of nodes do
7. if (depth = 1) then
8. beta ← min(beta, MMAB(player_side, depth-1, alpha, beta))
9. else
10. beta ← min(beta, MMAB(-player_side, depth-1, alpha, beta))
11. end if
12. if (alpha >= beta) then
13. break
14. end if
15. end for
16. return beta
17. else // WHITE: Maximizing Player
18. for each child of nodes do
19. if (depth = 1) then Fig. 4. Vertically-symmetric Dismath (VSB) board.
20. alpha ← max(alpha, MMAB(player_side, depth-1, alpha, beta))
21. else
22. alpha ← max(alpha, MMAB(-player_side, depth-1, alpha, beta))
23. end if
24. if (alpha >= beta) then
25. break
26. end if
27. end for
28. return alpha
29. end if

Utilizing the final score equation in (2) as the static game


board evaluation function, a minimax with alpha-beta
pruning algorithm (A1) based AI agent was formulated and
implemented for Dismath board game. The AI agent
performance is presented in the next section.

III. RESULTS AND DISCUSSIONS


The experimentation was carried out by implementing the
Dismath game in Python (3.6) utilizing Pygame module for Fig. 5. Evolutionary Strategy-based (ESB) Dismath board.
game interaction and graphical user interface (GUI).
TABLE III. DISMATH BOARD BALANCING EXPERIMENT RESULTS

Board Configurations, W/W Ratio (m=10,000 games per trial)


Trials Horizontal Vertical Diagonal Damath ES
Symmetric Symmetric Symmetric Style Board
(HSB) (VSB) (DSB) (DAB) (ESB)
1 0.992 0.940 0.471 0.472 0.994
2 0.979 0.972 0.478 0.457 0.984
3 0.961 0.926 0.450 0.478 0.995
4 0.939 0.968 0.473 0.457 0.979
5 0.999 0.999 0.468 0.480 0.986
Ave. 0.974 0.9608 0.468 0.469 0.988
Std.
Dev. 0.024 0.0288 0.0108 0.0113 0.007

TABLE IV. MINIMAX WITH ALPHA-BETA PRUNING AGENT RESULTS


Fig. 6. Diagonally-symmetric (DSB) Dismath board.
MMAB AI Agent vs Random Player (m=100 games)
MMAB
The results (Table III) showed that the best balanced board Depth Ave. no. Ave. time per
Win Loss Draw
of moves move (sec.)a
with respect to random play is the Evolutionary Strategy-
1
based board (ESB) (Fig. 4) followed by horizontally 50 48 2 25 0.00048
symmetric board (HSB). The results also demonstrated that a 2 100 0 0 26 0.0020
Damath-style operation configuration and diagonally
3
symmetric board has low win-win ratio which indicates that 100 0 0 20 0.0064
one side has significantly more wins than the other. Although 4 100 0 0 20 0.0122
ESB has the best board balance based on the results, the
5 100 0 0 20 0.0374
logical operations are arranged randomly, thus, hard to follow
especially if Dismath board game is designed for beginners. 6 100 0 0 19 0.0843
Thus, taking into account the configuration simplicity of the
7 100 0 0 20 0.2674
logical connectives, HSB and VSB are viable alternatives to
the complicated ESB, with a slightly lower W/W ratio. 8 100 0 0 19 0.4833
To characterize the developed Minimax with Alpha-Beta 9 100 0 0 17 1.9185
Pruning Algorithm (MMAB) based AI agent for Dismath, it 10 b
was matched (at various depth values) with a random player 10 0 0 20 3.4571
a.
that chose legal moves at random. Furthermore, the average The MMAB agent was run on a Desktop with an Intel I7-6700CPU @ 3.40GHz processor.
b.
number of moves to finish a game and the time duration per Due to time constraints, MMAB d = 10, experiment was performed at m =10 games only
move were also measured. The results (Table IV)
demonstrated that a random player can only beat the MMAB Another noticeable result from Table IV is the increase of
agent in Dismath game at Depth equal to 1, otherwise, MMAB time duration per move as the MMAB depth increases. This
AI agent clearly dominates in the higher depth values. The rise can be justified by the increasing computation as the
results also showed that the average moves per game is about minimax search tree gets deeper [12]. Thus, we can assume
25 or 26 if the players is playing close to random while this that the difficulty level of beating the MMAB AI agent
reduces to 19 or 20 moves when the other player is dominant. increases as the minimax search tree depth parameter gets
deeper. Ideally, a full tree should be searched for perfect
results, but same as checkers, Dismath game has
approximately 500 billion billion (5 × 1020) possible positions
[1] which is prohibitive for a normal gameplay if
implemented. Therefore, decreasing the depth level is a
necessary compromise considering the current technology.

Fig. 7. Damath-Style (DAB) Dismath board. Fig. 8. Increasing time-to-move as MMAB depth increases
IV. CONCLUSION REFERENCES
In this paper, Dismath, a new gamified educational tool for
propositional logic introduction to undergraduate computer [1] J. Schaeffer, N. Burch, Y. Bjornsson, A. Kishimoto, M. Muller, R.
engineering students was presented. Among the main Lake, P. Lu, and S. Sutphen, “Checkers is solved,” Science, vol. 317,
no. 5844, pp. 1518–1522, 2007.
contributions of this work is the introduction of the proposed
[2] F.Y. Wang, J.J. Zhang, X. Zheng, X. Wang, Y. Yuan, X. Dai, J. Zhang,
new game, Dismath, its rules, gameplay mechanics, and L. Yang, “Where does AlphaGo go: from church-turing thesis to
characterization and board balancing, and the development of AlphaGo thesis and beyond,” IEEE/CAA Journal of Automatica
the game AI agent based on Minimax tree search algorithm Sinica, 3(2), pp.113-120, 2016.
with Alpha Beta pruning (MMAB) for an automatized player. [3] D. Silver, T. Hubert, J. Schrittwieser, I. Antonoglou, M. Lai, A. Guez,
The results demonstrated the dominance of MMAB agent M. Lanctot, L. Sifre, L., D. Kumaran, T. Graepel, and T. Lillicrap, “
versus a random player. The difficulty of the AI agent can also Mastering chess and shogi by self-play with a general reinforcement
learning algorithm,” arXiv preprint arXiv:1712.01815, 2017.
be varied using the depth parameter of the Minimax search
tree at the expense of more time taken to make a decision or [4] P.A. Howard-Jones, T. Jay, A. Mason, and H. Jones, “Gamification of
learning deactivates the default mode network,” Frontiers in
to search the game tree. The results also showed that the psychology, 6, p.1891, 2016.
proposed game ends after about 19 to 26 moves, thus, [5] B. Taspinar, W. Schmidt, and H. Schuhbauer, “Gamification in
assuming worst-case scenario where each player utilizes education: a board game approach to knowledge acquisition,” Procedia
his/her 1 minute time slot per move, the game could extend up Computer Science, 99, pp.101-116, 2016.
to around 52 minute (about an hour). Thus, to avoid such [6] D.B. Jordaan, “Board Games in the Computer Science Class to
lengthy gameplay, a 30-minute overall game time limit is Improve Students’ Knowledge of the Python Programming Language,”
imposed. Future research will involve the utilization of the In 2018 International Conference on Intelligent and Innovative
Computing Applications (ICONIC), pp. 1-5, IEEE, 2018.
proposed Dismath learning tool in an actual classroom setting
[7] DepEd (Department of Education) , “2019 Division Mathematics
as a possible part of face-to-face activities in blended learning Festival and Metrobank-MTAP-DepEd Math Challenge,”
approach to computer engineering education. Memorandum No.2-s.2019.
[8] R. Ting, “The losing edge: the tension between the technical and
spectacle in sport,” Suri, vol. 7, no. 1, pp. 47–53, 2018.
[9] S.M. L. Ramos, I. G. Legaspi, J.A. C. Sabal, and G. S. Doroja, “Mobile
DaMath: a game for basic numeracy exercise,” International Journal
of Arts and Technology, vol. 6, no. 3, p. 246, 2013.
[10] R.J. Rubin, J. Marcelino, R. Mortel, and M.R.C. Lapinid, “Activity-
based teaching of integer concepts and its operations,” In DLSU
Research Congress, pp. 6-8, 2014.
[11] F. Chiarello, and M.G. Castellano, “Board games and board game
design as learning tools for complex scientific concepts: some
experiences,” International Journal of Game-Based Learning
(IJGBL), 6(2), pp.1-14, 2016.
[12] A. Plaat, J. Schaeffer, W. Pijls, and A. De Bruin, “A new paradigm for
minimax search,” arXiv preprint arXiv:1404.1515, 2014.

You might also like