﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with MathML3 v1.2 20190208//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd">
<article
    xmlns:mml="http://www.w3.org/1998/Math/MathML"
    xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="article">
  <front>
    <journal-meta>
      <journal-id journal-id-type="publisher-id">JML</journal-id>
      <journal-title-group>
        <journal-title>Journal of Mathematics Letters</journal-title>
      </journal-title-group>
      <issn pub-type="epub"></issn>
      <issn pub-type="ppub"></issn>
      <publisher>
        <publisher-name>Science Publications</publisher-name>
      </publisher>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.31586/jml.2022.496</article-id>
      <article-id pub-id-type="publisher-id">JML-496</article-id>
      <article-categories>
        <subj-group subj-group-type="heading">
          <subject>Article</subject>
        </subj-group>
      </article-categories>
      <title-group>
        <article-title>
          Notes about Winning Strategies for Some Combinatorial Games
        </article-title>
      </title-group>
      <contrib-group>
<contrib contrib-type="author">
<name>
<surname>Cherniichuk</surname>
<given-names>Halyna P.</given-names>
</name>
<xref rid="af1" ref-type="aff">1</xref>
</contrib>
<contrib contrib-type="author">
<name>
<surname>Krykun</surname>
<given-names>Ivan H.</given-names>
</name>
<xref rid="af1" ref-type="aff">1</xref>
<xref rid="af2" ref-type="aff">2</xref>
<xref rid="cr1" ref-type="corresp">*</xref>
</contrib>
      </contrib-group>
<aff id="af1"><label>1</label> Department of Applied Mathematics, Vasyl&#x02019; Stus Donetsk National University, Vinnytsia, Ukraine</aff>
<aff id="af2"><label>2</label> Department of Theory of Control Systems of Institute of Applied Mathematics and Mechanics of NAS of Ukraine, Sloviansk, Ukraine </aff>
<author-notes>
<corresp id="c1">
<label>*</label>Corresponding author at: Department of Applied Mathematics, Vasyl’ Stus Donetsk National University, Vinnytsia, Ukraine
</corresp>
</author-notes>
      <pub-date pub-type="epub">
        <day>26</day>
        <month>10</month>
        <year>2022</year>
      </pub-date>
      <volume>1</volume>
      <issue>1</issue>
      <history>
        <date date-type="received">
          <day>26</day>
          <month>10</month>
          <year>2022</year>
        </date>
        <date date-type="rev-recd">
          <day>26</day>
          <month>10</month>
          <year>2022</year>
        </date>
        <date date-type="accepted">
          <day>26</day>
          <month>10</month>
          <year>2022</year>
        </date>
        <date date-type="pub">
          <day>26</day>
          <month>10</month>
          <year>2022</year>
        </date>
      </history>
      <permissions>
        <copyright-statement>&#xa9; Copyright 2022 by authors and Trend Research Publishing Inc. </copyright-statement>
        <copyright-year>2022</copyright-year>
        <license license-type="open-access" xlink:href="http://creativecommons.org/licenses/by/4.0/">
          <license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p>
        </license>
      </permissions>
      <abstract>
        We study the theory of combinatorial games and find winning strategies for players. The algorithmic implementation of the winning strategies for the game TacTix is presented and the software implementation for this game in Python programming language is implemented. The program has a console interface and allows one to check the winning strategies in practice.
      </abstract>
      <kwd-group>
        <kwd-group><kwd>Combinatorial Game Theory</kwd>
<kwd>Greedy algorithm</kwd>
<kwd>Symmetric algorithm</kwd>
<kwd>TacTix</kwd>
<kwd>Nim</kwd>
<kwd>Winning Strategies.</kwd>
</kwd-group>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec1">
<title>Introduction</title><p>Combinatorial game theory is a mathematical theory that studies two-person games where at each moment in time there is a position that the players change accordingly to achieve victory. This theory does not study games involving chance.</p>
<p>Combinatorial games are games played by two players without random moves and with complete information, i.e. all moves are known to both players. Players take turns making moves, thus changing positions from one to another, until the final position is reached, in which there are no possible moves. When the final position is reached, one of the players is declared the winner, and the other - is the loser.</p>
<p>Combinatorial games as a subject of research began to attract the attention of mathematicians in the early twentieth century. The beginning of the study was the article by Charles Bouton [
<xref ref-type="bibr" rid="R1">1</xref>].</p>
<p>Game theory is applied in various fields of human activity: politics, biology, cybernetics, economics, military affairs, etc. Each player has strategies that he can apply. The interaction of two players creates a situation where each player gets a certain result: win or lose. When choosing a strategy, it is necessary to take into account not only the maximum gain for yourself, but also the possible steps of the opponent and their impact on the situation as a whole [
<xref ref-type="bibr" rid="R2">2</xref>,<xref ref-type="bibr" rid="R3">3</xref>].</p>
<p>Combinatorial games have important features that distinguish them from other games (i.e. gambling, cooperative, antagonistic, and others). Namely [
<xref ref-type="bibr" rid="R3">3</xref>]: </p>
<p>There are two players who take turns;</p>
<p>There are no random factors - like shuffling cards or using dice;</p>
<p>There is complete information - both players know all possible moves;</p>
<p>The game must end with one of the players winning, there can be no draw.</p>
<p>The last move determines the winner;</p>
<p>There are two types of the game: "normal game": the player who made the last move wins; "miser game": the player who made the last move loses.</p>
</sec><sec id="sec2">
<title>Model of combinatorial game TacTix</title><p>TacTix is a combinatorial game, which is a derivative of the more general Nim game, invented by P. Hayne [
<xref ref-type="bibr" rid="R4">4</xref>]. It refers to logical or mathematical puzzles. TacTix is a geometric variant of the more general game Nim [
<xref ref-type="bibr" rid="R3">3</xref>,<xref ref-type="bibr" rid="R5">5</xref>]. The game is played on a board of size N x N, filled with some chips (coins, stones). In one move, a player can pick up several chips from a row or column. The number of chips taken in one move cannot be more than the number of chips in the row or column. Also, the selected chips must be located next to each other, in the same row or column.</p>
<p></p>
<p>There are winning strategies for players (for "normal" game) [
<xref ref-type="bibr" rid="R5">5</xref>]:</p>
<p>For the first player: if N is odd, take the centerpiece and copy every move of the opponent symmetrically. Eventually the player takes the last piece and wins.</p>
<p>For the second player: if N is even, then you need to copy the opponent's moves symmetrically. Eventually, the player will take the last chip and win.</p>
<p></p>
<p>TacTix refers to unbiased games. An unbiased game is an equal combinatorial game with the following properties: the action or move that is available to a player depends only on the state of the game, but does not depend on who makes the move; if a player is unable to make a move, he loses; the game must always end [
<xref ref-type="bibr" rid="R5">5</xref>]. The termination condition can be changed to obtain the so-called miner's game - the player who made the last move loses. The impartiality condition makes it unimportant who makes the move; each position has a certain outcome taking into account who made the move.</p>
<p>The TacTix game has the property of being finite [
<xref ref-type="bibr" rid="R5">5</xref>]. A finite game is a game that starts from any position, and the final result is always reached after a certain number of moves, which depends only on the initial position. Thus the game ends when there are no pieces left on the board. Therefore, the number of moves played is equal, at most, to the number of chips on the board.</p>
</sec><sec id="sec3">
<title>Winning strategies for Nim-like games</title><p>TacTix is one of the Nim-like games. The differences are that the game is played on a board of size N x N, in one move a player can take several adjacent chips from a row or column, but not more than the number of chips in a row or column.</p>
<p>The analyzed studies [
<xref ref-type="bibr" rid="R3">3</xref>,<xref ref-type="bibr" rid="R4">4</xref>,<xref ref-type="bibr" rid="R6">6</xref>] highlight general approaches to Nim-like games. These approaches are based on the rules of the Nim game: there are several rows or piles of chips (in the classic version - 3 piles); any number of items (more than zero) from one pile can be taken in one move. In the "normal" game the player who took the last item wins, in the miser game this player loses.</p>
<p>Different rules for removing chips from the playing field make it possible to divide Nim-like games into several types. We give an overview of existing results for Nim-like games using [
<xref ref-type="bibr" rid="R6">6</xref>].</p>
<p><bold>Game I. For each move a player can remove from 1 to 3 chips from the board.</bold></p>
<p><bold>Theorem 1.</bold> <italic>For game I, the game is winning for the second player at each stage if the number n of chips remaining on the board at this stage is a multiple of 4, and winning for the first player in all other cases. The winning strategy for the first player is to remove n mod 4 chips (the number of chips that is divisible by 4).</italic></p>
<p></p>
<p><bold>Game II. A player can take any number of chips less than or equal to the number of chips taken by the opponent on the previous turn. The first player can remove any number of chips, except all at once.</bold></p>
<p>The analysis of winning strategies for this type of game shows that this type of game can be reduced to the analysis of binary decomposition of numbers. Charles Bouton in his article [
<xref ref-type="bibr" rid="R1">1</xref>] described the analysis of the game of Nim using binary decomposition. Each combination of chips was called "dangerous" or "safe". If the position after the next move of the player guarantees him a win, then this position is safe, otherwise the position is unsafe. To determine whether a position is safe or not, the number of chips in each row must be written in binary. If the sum in each column (digit) is zero or even, then the position is safe. If the sum in at least one column is odd, then the position is unsafe. </p>
<p>In this type of Nim-like games, if a player picks up 1 chip at a certain stage, then in the following moves players can pick up only 1 chip. Since according to the rules of the "normal" game the one who takes the last chip wins, the player at the stage when the number of chips remaining on the board becomes odd can win the game by taking 1 chip.</p>
<p>What should the first player do if the number of remaining chips is even? If he takes only 1 chip, he loses the game. If he takes 2 chips, the next moves of the players will be a repetition of taking 2 chips. Therefore, the first player at the stage when the number of remaining chips is an odd number or a multiple of 2 can win the game by taking 2 chips.</p>
<p>If the number of remaining chips is an even number or a multiple of 2, in particular a multiple of 4, then the moves of the players starting from this stage will be a repetition of taking 4 chips, and therefore the player starting the game at a stage when the number of remaining chips is an odd number or a multiple of 4 can win the game by taking 4 chips. </p>
<p></p>
<p><bold>Theorem 2.</bold> <italic>In Game II, at the stage when there are </italic><math><semantics><mrow><msup><mrow><mn>2</mn></mrow><mrow><mi mathvariant="bold-italic">p</mi></mrow></msup><mo>(</mo><mn>2</mn><mi mathvariant="bold-italic">p</mi><mo>+</mo><mn>1</mn><mo>)</mo><mi mathvariant="bold-italic"> </mi></mrow></semantics></math><italic>chips left on the board, the game is won by the first player if and only if the rules of the game allow to take </italic><math><semantics><mrow><msup><mrow><mn>2</mn></mrow><mrow><mi mathvariant="bold-italic">p</mi></mrow></msup></mrow></semantics></math><italic> chips at this stage.</italic></p>
<p>An example of using Theorem 2: a game according to the rules of Game II, started with <math><semantics><mrow><msup><mrow><mn>2</mn></mrow><mrow><mi mathvariant="bold-italic">p</mi></mrow></msup></mrow></semantics></math> chips on the board, is always won by the second player, since the player who started the game cannot remove all the chips. A Game II game started with a different number of chips than <math><semantics><mrow><msup><mrow><mn>2</mn></mrow><mrow><mi mathvariant="bold-italic">p</mi></mrow></msup></mrow></semantics></math> is won by the player who started the game.</p>
<p>Thus, the winning strategies for Game II were determined. However, it is possible to derive these strategies using another idea that can be applied to games with more complex rules.</p>
<p>Since the number of balls that can be removed from the playing field is constantly changing during the game, we define a number <italic>w(n)</italic>, which denotes the smallest number of balls that must be removed to win at the stage when there are n chips left.</p>
<p></p>
<p><bold>Theorem 3.</bold> <italic>The winning strategy for a player who starts Game II with n chips on the board is to take away such a number of chips that the number of chips on the board m, which became after the first player's move, in the binary expansion would have zero in the place of the rightmost one in the binary expansion of the number n.</italic></p>
<p></p>
<p><bold>Game III. A player can remove from the playing field the number of chips that is less than or equal to twice the number of chips taken by the opponent in the previous turn. The first player can remove any number of chips, except all at once.</bold></p>
<p></p>
<p>For this game, the sequence of Fibonacci numbers plays an important role in finding winning strategies.</p>
<p></p>
<p><bold>Theorem 4.</bold> <italic>In game III, at the stage when the number of chips remaining on the board is n, the game is won by the first player if and only if the rules of the game allow to take l(n) chips, where l(n) is some number from the Fibonacci sequence corresponding to the number n (for a detailed explanation see [
<xref ref-type="bibr" rid="R6">6</xref>]).</italic></p>
</sec><sec id="sec4">
<title>Winning strategies for the TacTix game</title><p>Given that the TacTix game is a variant of the Nim game, the analysis of the above results suggests that they remain valid for TacTix as well. However, the winning strategies for TacTix are much simpler than for Nim. Therefore, the analysis of different types of the game (given above) was carried out, on the basis of which the winning strategies for TacTix were formulated, and the software implementation of the obtained strategies was performed. </p>
<p>The standard game of TacTix is played on a 4 x 4 playing field filled with chips. Thus, the player can pick up from 1 to 4 adjacent chips in the same row or column.</p>
<p>Let's consider a variation of the rules - Game I from the previous paragraph for the game TacTix. Let's explore how the winning strategies are determined depending on the number of chips remaining on the playing field.</p>
<p>Stages in which the number of chips is <italic>n</italic> = 1; 2; 3 are winning for the first player, since the player can take all the chips remaining on the playing field in one row or column at a time, provided that these chips are located next to each other. </p>
<p>The stage with <italic>n</italic> = 4 remaining chips is winning for the Second player, since any move of the First player leads to a winning situation for the Second player.</p>
<p>At the stage <italic>n</italic> = 5 chips, if the first player takes 2 or 3 chips, then 3 or 2 chips are left and thus the opponent wins.</p>
<p>In addition to the strategies presented in Theorems 1 &#x26;#x02013; 4, the so-called "greedy" or "symmetric" algorithms can also be used for the TacTix game. They are easier to apply, to some extent intuitive, but it is worth remembering the need to adjust the strategy during the game.</p>
<p>The greedy algorithm [
<xref ref-type="bibr" rid="R7">7</xref>] is a simple and straightforward algorithm that makes the best decision based on the data available at this stage. The player who applies this algorithm does not worry about possible consequences, but hopes to get the optimal solution. In other words, the player tries to take as many chips as possible from the field in one move.</p>
<p>It is advisable to use this algorithm at the first attempt to play a new game, especially if the opponent is an expert. Thus, you will not waste time searching for successful moves. But it is worth noting that this algorithm does not always work. For games such as TacTix and Nim, the use of this algorithm may not lead to an optimal solution, but on the contrary give the worst possible solution.</p>
<p>Symmetric algorithm [
<xref ref-type="bibr" rid="R7">7</xref>] is an intuitively obvious strategy. Every time the opponent makes a move in one part of the board, the player mirrors this move in the other part of the board.</p>
<p>To successfully use the symmetric algorithm of the game, it is not necessary to leave the opponent a move that will eliminate the possibility of repeating the move (for example, in the center of the board).</p>
</sec><sec id="sec5">
<title>Software implementation of the game TacTix</title><p>Using the above algorithms/strategies, we have created a software implementation of the game TacTix. This implementation is written in Python programming language and has a console interface. The game is played according to the rules of Game I and is played against the computer. All rules are described at the beginning of the game. Also, for convenience, there are hints about possible moves and their number, warnings about the absence of a move, or an erroneous move.</p>
<p>The size of the playing field is 4 x 4. One randomly determines who makes the first move (the player or the computer), next moves will take place in turn. </p>
<p>At the beginning of the game, the player is asked to choose his game symbol ("X" or "O"). After selecting the game symbols, the screen displays an empty field and prompts the player to make a move (if the player moves first) or displays the field with the computer's first move and prompts the player to make his move (otherwise). According to the selected symbol "X" or "O", the player and the computer take turns filling the whole board. </p>
<fig id="fig1">
<label>Figure 1</label>
<caption>
<p>Screenshot of the start of the game with the first computer move</p>
</caption>
<graphic xlink:href="496.fig.001" />
</fig><p>Computer&#x26;#x02019;s moves are made according to the described winning strategy (if there is a winning situation for the computer) or to prevent the possibility of implementing the winning strategy for the player (otherwise).</p>
<fig id="fig2">
<label>Figure 2</label>
<caption>
<p>Screenshot of the end of the game</p>
</caption>
<graphic xlink:href="496.fig.002" />
</fig><p>We have developed an algorithm for the game, which is shown in the flowchart below.</p>
<fig id="fig3">
<label>Figure 3</label>
<caption>
<p>The flowchart for the implementation of the game TacTix</p>
</caption>
<graphic xlink:href="496.fig.003" />
</fig><p>The program code for this implementation of the game TacTix (according to Game I rules) is given in Appendix A.</p>
<p></p>
<p></p>
</sec><sec id="sec6">
<title>Conclusions and prospects for further research</title><p>The developed model of the game TacTix (according to the rules of the Game I) shows in practice the application of the algorithm. During the game, you can clearly see the effectiveness of the strategy, as well as identify situations when the player wins for sure or when one wrong move leads to a computer win.</p>
<p>This model of the game will be further improved, namely the ability to choose the size and shape of the board to make the game more interesting and more complex. Also in the future, it will developed algorithms for the game TacTix according to the rules described as Game II and Game III.  </p>
<p>The proposed model of the combinatorial game will be enhanced using recent studies of random processes [8&#x26;#x02013;16] for study games involving chance. About the application of combinatorial games, there is a lot of information in [
<xref ref-type="bibr" rid="R2">2</xref>,<xref ref-type="bibr" rid="R3">3</xref>,<xref ref-type="bibr" rid="R7">7</xref>,<xref ref-type="bibr" rid="R15">15</xref>,<xref ref-type="bibr" rid="R17">17</xref>,<xref ref-type="bibr" rid="R18">18</xref>].</p>
<p></p>
<p></p>
<p><bold>Author Contributions:</bold> All authors have read and agreed to the published version of the manuscript.</p>
<p><bold>Funding:</bold> This research received no external funding.</p>
<p><bold>Acknowledgments:</bold> The authors express their heartfelt gratitude to the brave soldiers of the Ukrainian Armed Forces who protect the lives of the authors and their families from Russian bloody murderers since 2014.</p>
<p><bold>Conflicts of Interest:</bold> The authors declare no conflict of interest.</p>
</sec><sec id="sec7">
<title>Program code for the game</title><p></p>
<p># "TacTix" Game</p>
<p>import random</p>
<p>print("""</p>
<p>-------------------------------------------------------------------------------</p>
<p>                            "TacTix" Game</p>
<p>-------------------------------------------------------------------------------</p>
<p>RULES: </p>
<p>         1 - The player plays with the computer</p>
<p>         2 - At one time you can fill from 1 to 3 cells</p>
<p>         3 - The one who fills the last cell wins</p>
<p>         4 - HAVE A GOOD GAME!</p>
<p>-------------------------------------------------------------------------------</p>
<p>""")</p>
<p>def drawBoard(board):</p>
<p>    print ('    |    |    |')</p>
<p>    print (' '  + board[
<xref ref-type="bibr" rid="R13">13</xref>] + '  |  '  + board[
<xref ref-type="bibr" rid="R14">14</xref>] + ' |   ' + board[
<xref ref-type="bibr" rid="R15">15</xref>] + '| ' + board[
<xref ref-type="bibr" rid="R16">16</xref>])</p>
<p>    print ('    |    |    |')</p>
<p>    print ('-------------------')</p>
<p>    print ('    |    |    |')</p>
<p>    print (' '  + board[
<xref ref-type="bibr" rid="R9">9</xref>]  + '  | ' + board[
<xref ref-type="bibr" rid="R10">10</xref>]  + '  |   ' + board[
<xref ref-type="bibr" rid="R11">11</xref>] + '| ' + board[
<xref ref-type="bibr" rid="R12">12</xref>])</p>
<p>    print ('    |    |    |')</p>
<p>    print ('-------------------')</p>
<p>    print ('    |    |    |')</p>
<p>    print (' '  + board[
<xref ref-type="bibr" rid="R5">5</xref>]  + '  | ' + board[
<xref ref-type="bibr" rid="R6">6</xref>]   + '  |   ' + board[
<xref ref-type="bibr" rid="R7">7</xref>]  + '| ' + board[
<xref ref-type="bibr" rid="R8">8</xref>])</p>
<p>    print ('    |    |    |')</p>
<p>    print ('-------------------')</p>
<p>    print ('    |    |    |')</p>
<p>    print (' '  + board[
<xref ref-type="bibr" rid="R1">1</xref>]  + '  | ' + board[
<xref ref-type="bibr" rid="R2">2</xref>]   + '  |   ' + board[
<xref ref-type="bibr" rid="R3">3</xref>]  + '| ' + board[
<xref ref-type="bibr" rid="R4">4</xref>])</p>
<p>    print ('    |    |    |')</p>
<p>def inputPlayerLetter():</p>
<p>    # The player chooses which label (letter) will fill the cells</p>
<p>    letter = ''</p>
<p>    while not(letter == 'X' or letter == 'O'):</p>
<p>        print ('What letter do you choose X or O?')</p>
<p>        letter = input().upper()</p>
<p>    # The first element corresponds to the player and the second element corresponds to the computer</p>
<p>        if letter == 'X':</p>
<p>            return ['X','O']</p>
<p>        else:</p>
<p>            return ['O','X']</p>
<p>def whoGoesFirst():</p>
<p>    if random.randint(0,1) == 0:</p>
<p>        return 'computer'</p>
<p>    else:</p>
<p>        return 'player'</p>
<p>def playAgain():</p>
<p>    # Function for replay (when the player wants to play again)</p>
<p>    print(' Would you like to play again? (yes or no)')</p>
<p>    return input().lower().startswith('y')</p>
<p>def makeMove(board, letter, move):</p>
<p>    board[move] = letter</p>
<p>def isWinner(board, letter, getComputerMove):</p>
<p>    # The loser is the one who fills in the last box</p>
<p>    if isBoardFull(board):        </p>
<p>        return True</p>
<p>    return False </p>
<p>def getBoardCopy(board):</p>
<p>    dupeBoard = [
]</p>
<p>    for i in board:</p>
<p>        dupeBoard.append(i)</p>
<p>    return dupeBoard</p>
<p>def isSpaceFree(board,  move):</p>
<p>    return board[move] == ' '</p>
<p>def getPlayerMove(board, move_index, previous_moves):</p>
<p>    def isValidMove(move):</p>
<p>        moves = previous_moves + [move]</p>
<p>        return all( (m-1) // 3 == (moves[
]-1) // 3 for m in moves ) or all( m % 3 == moves[
] % 3 for m in moves)</p>
<p>    move = ' '</p>
<p>    possible_moves ='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16' .split()</p>
<p>    while move not in possible_moves or not isSpaceFree(board, int(move)) or not isValidMove(int(move)):</p>
<p>        if move_index == 0:</p>
<p>            print (' What is your next move?')</p>
<p>        else:</p>
<p>            if move in possible_moves and not isValidMove(int(move)):</p>
<p>                print('You can select only those cells that are in the same row or column as already selected cells ')</p>
<p>            text_cells = 'cells'</p>
<p>            if 3 - move_index == 1:</p>
<p>                text_cells = ' cell '</p>
<p>            print ('You can choose more ' + str(3 - move_index) + ' ' + text_cells + '. Press enter to no longer choose ')</p>
<p>            if len(move) == 0:</p>
<p>                return None</p>
<p>        move = input()</p>
<p>    return int(move)</p>
<p>def chooseRandomMoveFromList(board, moveList):</p>
<p>    possibleMoves = [
]</p>
<p>    for i in moveList:</p>
<p>        if isSpacefree(board, i):</p>
<p>            possibleMoves.append(i)</p>
<p>        if len(possibleMoves) !=0:</p>
<p>            return random.choice(possibleMoves)</p>
<p>        else:</p>
<p>            return None</p>
<p>def getComputerMove(board, computerLetter):</p>
<p>    if computerLetter == 'X':</p>
<p>        playerLetter = 'O'</p>
<p>    else:</p>
<p>        playerLetter = 'X'</p>
<p>    for i in range(1,17):</p>
<p>        copy = getBoardCopy(board)</p>
<p>        if isSpaceFree(copy, i):</p>
<p>            makeMove(copy, computerLetter, i)</p>
<p>            return i</p>
<p>    raise Exception("Board is full")</p>
<p>def isBoardFull(board):</p>
<p>    for i in range(1, 17):</p>
<p>        if isSpaceFree(board, i):</p>
<p>            return False</p>
<p>    return True</p>
<p>while True:</p>
<p>    theBoard = [
]*17</p>
<p>    playerLetter, computerLetter = inputPlayerLetter()</p>
<p>    turn = whoGoesFirst()</p>
<p>    print('  ' + turn + ' will move first ')</p>
<p>    gameIsPlaying = True</p>
<p>    while gameIsPlaying:</p>
<p>        if turn == 'player':</p>
<p>            drawBoard(theBoard)</p>
<p>            prev_moves = [
]</p>
<p>            for i in range(3):</p>
<p>                move = getPlayerMove(theBoard, i, prev_moves)</p>
<p>                if move is None:</p>
<p>                    turn = 'computer'</p>
<p>                    break</p>
<p>                makeMove(theBoard, playerLetter, move)</p>
<p>                prev_moves.append(move)</p>
<p>                if isBoardFull(theBoard):</p>
<p>                    drawBoard(theBoard)</p>
<p>                    print('You win')</p>
<p>                    gameIsPlaying = False</p>
<p>                else:</p>
<p>                    turn = 'computer'</p>
<p>        else:</p>
<p>            move = getComputerMove(theBoard, computerLetter)</p>
<p>            makeMove(theBoard, computerLetter, move)</p>
<p>            column_or_row = random.choice(['column', 'row'])</p>
<p>            amount = random.randint(0, 3)</p>
<p>            for i in range(amount):</p>
<p>                if column_or_row == 'row':</p>
<p>                    new_move = move + i+1</p>
<p>                    if (new_move-1) // 3 != (move-1) // 3:</p>
<p>                        break</p>
<p>                else:</p>
<p>                    new_move = move + 3*(i+1)</p>
<p>                    print('nm: ' + str(new_move) + ' ' + str(move))</p>
<p>                    if new_move &lt; 0 or new_move &gt; 16:</p>
<p>                        break</p>
<p>                if isSpaceFree(theBoard, new_move):</p>
<p>                    makeMove(theBoard, computerLetter, new_move)</p>
<p>                else:</p>
<p>                    break</p>
<p>            if isBoardFull(theBoard): </p>
<p>                drawBoard(theBoard)</p>
<p>                print('You have lost')</p>
<p>                gameIsPlaying = False</p>
<p>            else:</p>
<p>                turn = 'player'</p>
<p>    if not playAgain():</p>
<p>        break</p>
</sec>
  </body>
  <back>
    <ref-list>
      <title>References</title>
      
<ref id="R1">
<label>[1]</label>
<mixed-citation publication-type="other">Bouton, C.L. Nim, &#x00430; Game with a Complete Mathematical Theory. The Annals of Mathematics 1901-1902, 2nd Ser., Vol. 3, No. 1/4. pp. 35-39.
</mixed-citation>
</ref>
<ref id="R2">
<label>[2]</label>
<mixed-citation publication-type="other">Siegel, A.N. Combinatorial Game Theory; American Mathematical Society: Providence, USA, 2013.
</mixed-citation>
</ref>
<ref id="R3">
<label>[3]</label>
<mixed-citation publication-type="other">El-Seidy, E.; Hussein, S.E.S.; Alabdala, A.T. Models of Combinatorial Games and Some Applications: A Survey. Journal of Game Theory 2016, Vol. 5(2), pp. 27-41.
</mixed-citation>
</ref>
<ref id="R4">
<label>[4]</label>
<mixed-citation publication-type="other">Oltean, M. Evolving Winning Strategies for Nim-like Games, In IFIP Student Forum, 2004, pp. 353-364.
</mixed-citation>
</ref>
<ref id="R5">
<label>[5]</label>
<mixed-citation publication-type="other">Iacono, J., Mazur, K. Tactix on an S-shaped Board. Proceedings of 22nd Annual Fall Workshop on Computational Geom-etry, College Park MD, 2012, November, 9-10, pp. 17-18.
</mixed-citation>
</ref>
<ref id="R6">
<label>[6]</label>
<mixed-citation publication-type="other">Ooya, T.; Akiyama, J. Impact of binary and Fibonacci expansions of numbers on winning strategies for Nim-like games, International Journal of Mathematical Education in Science and Technology 2003, Vol. 34, No. 1, pp. 121-128.
</mixed-citation>
</ref>
<ref id="R7">
<label>[7]</label>
<mixed-citation publication-type="other">Albert, M.H.; Nowakowski, R.J.; Wolfe, D. Lessons in play: an introduction to combinatorial game theory, 2nd ed.; CRC Press: Boca Raton, Florida:, USA, 2019.
</mixed-citation>
</ref>
<ref id="R8">
<label>[8]</label>
<mixed-citation publication-type="other">Krykun, I.H. Large deviation principle for stochastic equations with local time. Theory of Stochastic Processes 2009. 15(31), No. 2. pp. 140-155.
</mixed-citation>
</ref>
<ref id="R9">
<label>[9]</label>
<mixed-citation publication-type="other">Krykun, I.H. Functional law of the iterated logarithm type for a skew Brownian motion. Teorija Imovirnostej ta Ma-tematychna Statystyka 2012, 87. pp. 60-77 (in Ukrainian)
</mixed-citation>
</ref>
<ref id="R10">
<label>[10]</label>
<mixed-citation publication-type="other">Krykun, I.H.; Makhno, S.Ya. The Peano phenomenon for It&#x000f4; equations. Journal of Mathematical Sciences 2013, 192, Issue 4, pp. 441-458. DOI: 10.1007/s10958-013-1407-5
</mixed-citation>
</ref>
<ref id="R11">
<label>[11]</label>
<mixed-citation publication-type="other">Krykun, I.H. Functional law of the iterated logarithm type for a skew Brownian motion. Theory of Probability and Mathe-matical Statistics 2013, 87, pp. 79-98. DOI: 10.1090/S0094-9000-2014-00906-0
</mixed-citation>
</ref>
<ref id="R12">
<label>[12]</label>
<mixed-citation publication-type="other">Krykun, I.H. Convergence of skew Brownian motions with local times at several points that are contracted into a single one. Journal of Mathematical Sciences 2017, 221, Issue 5, pp. 671-678. DOI: 10.1007/s10958-017-3258-y
</mixed-citation>
</ref>
<ref id="R13">
<label>[13]</label>
<mixed-citation publication-type="other">Krykun, I.H. The Arc-Sine Laws for the Skew Brownian Motion and Their Interpretation. Journal of Applied Mathematics and Physics 2018, 6, No. 2, pp. 347-357. DOI: 10.4236/jamp.2018.62033
</mixed-citation>
</ref>
<ref id="R14">
<label>[14]</label>
<mixed-citation publication-type="other">Krykun, I. H. The Arctangent Regression and the Estimation of Parameters of the Cauchy Distribution. Journal of Mathe-matical Sciences 2020, 249, Issue 5, pp. 739-753.
</mixed-citation>
</ref>
<ref id="R15">
<label>[15]</label>
<mixed-citation publication-type="other">Krykun, I.H. The arcsine laws in the modelling of the natural processes depending on random factors. In Physical and mathematical justification of scientific achievements: collective monograph, Primedia eLaunch LLC: Boston, USA, 2020; pp. 24-33. DOI: 10.46299/ISG.2020.MONO.PHYSICAL.III
</mixed-citation>
</ref>
<ref id="R16">
<label>[16]</label>
<mixed-citation publication-type="other">Krykun, I.H. New Approach to Statistical Analysis of Election Results. International Journal of Mathematical, Engineering, Biological and Applied Computing 2022, 1, No. 2, pp. 68-76. DOI: 10.31586/ijmebac.2022.466
</mixed-citation>
</ref>
<ref id="R17">
<label>[17]</label>
<mixed-citation publication-type="other">Knorps, M. NIM and combinatorial games on graphs. Faculty of Applied Physics and Mathematics, Gda&#x00144;sk University of Technology, 2007.
</mixed-citation>
</ref>
<ref id="R18">
<label>[18]</label>
<mixed-citation publication-type="other">Milvang-Jensen, B.C.A. Combinatorial games, theory and applications, 2000.
</mixed-citation>
</ref>
    </ref-list>
  </back>
</article>