finallya bit of fun to close out this our last examplepytoeimplements an artificially intelligent tic-tac-toe (sometimes called "naughts and crosses"gameplaying program in python most readers are probably familiar with this simple gameso won' dwell on its details in shortplayers take turns marking board positionsin an attempt to occupy an entire rowcolumnor diagonal the first player to fill such pattern wins in pytoeboard positions are marked with mouse clicksand one of the players is python program the game board itself is displayed with simple tkinter guiby defaultpytoe builds game board (the standard tic-tac-toe setup)but it can be configured to build and play an arbitrary game when it comes time for the computer to select moveartificial intelligence (aialgorithms are used to score potential moves and search tree of candidate moves and countermoves this is fairly simple problem as gaming programs goand the heuristics used to pick moves are not perfect stillpytoe is usually smart enough to spot wins few moves in advance of the user running pytoe pytoe' gui is implemented as frame of expandable packed labelswith mouse-click bindings on the labels to catch user moves the label' text is configured with the player' mark after each movecomputer or user the guimaker class we coded earlier in the prior (example - is also reused here again to add simple menu bar at the top (but no toolbar is drawn at the bottombecause pytoe leaves its format descriptor emptyby defaultthe user' mark is "xand pytoe' is " figure - shows pytoe run from pygadgets with its status pop-up dialogon the verge of beating me one of two ways figure - shows pytoe' help pop-up dialogwhich lists its command-line configuration options you can specify colors and font sizes for board labelsthe player who moves firstthe mark of the user ("xor " ")the board size (to override the default)and the move selection strategy for the computer ( "minimaxperforms move tree search to spot wins and lossesand "expert and "expert use static scoring heuristics functionsthe ai gaming techniques used in pytoe are cpu intensiveand some computer move selection schemes take longer than othersbut their speed varies mostly with the speed of your computer move selection delays are fractions of second long on my machine for game boardfor all "-modemove-selection strategy options figure - shows an alternative pytoe configuration (shown running its top-level script directly with no arguments)just after it beat me despite the scenes captured for this bookunder some move selection optionsi do still win once in while in complete gui programs