Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Preloaded Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Monterey Phoenix
MP Model Collection
Preloaded Examples
Commits
60df8ae3
Commit
60df8ae3
authored
3 years ago
by
Giammarco, Kristin M
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
0cfeb35b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
models/Application_examples/Tic_tac_toe.mp
+205
-0
205 additions, 0 deletions
models/Application_examples/Tic_tac_toe.mp
with
205 additions
and
0 deletions
models/Application_examples/Tic_tac_toe.mp
0 → 100644
+
205
−
0
View file @
60df8ae3
/*┬────────────────────────────────────────────────────────┐
│*│ ┌─[ Title and Authors ]──────────────────────────────┐ │
│*│ │ Model of Tic Tac Toe │ │
│*│ │ Created by Michael Collins in December, 2021. │ │
│*│ │ Modified by Michael Collins and Pamela Dyer │ │
│*│ │ in January through May, 2022. │ │
│*│ │ | |
│*│ │ Thanks to Emma Werking for her contributions. │ │
│*│ └────────────────────────────────────────────────────┘ │
│*│ │
│*│ ┌─[ Purpose ]────────────────────────────────────────┐ │
│*│ │ To demonstrate using MP to model simple strategies │ │
│*│ │ in the context of a game of Tic-tac-toe. │ │
│*│ └────────────────────────────────────────────────────┘ │
│*│ │
│*│ ┌─[ Description ]────────────────────────────────────┐ │
│*│ │ How to play Tic-tac-toe: | |
│*│ │ The game board is a 3 by 3 grid of cells. | |
│*│ │ The player who goes first is known as 'X'. | |
│*│ │ The player who goes second is known as 'O'. | |
│*│ │ The players alternate placing Xs and Os on the | |
│*│ │ board until either one of the players has three in| |
│*│ │ a line or until all cells on the grid are filled. | |
│*│ │ | |
│*│ │ The goal is to never lose a game of Tic-Tac-Toe. | |
|*| | | |
│*│ │ The following rules simplify the strategy: | |
│*│ │ 1) X never makes any mistakes. │ │
|*| | 2) O makes at most one mistake. | |
│*│ │ 3) X always chooses a corner on the first move | |
|*| | of the game. | |
|*| | | |
│*│ │ Strategy: List all possible 2nd moves of the | |
|*| | game. Show how X can win or play to a | |
|*| | draw in each case by listing every move. | |
|*| | When playing the game as X, use these | |
|*| | predetermined games as your directions | |
|*| | for how to play. | |
│*│ └────────────────────────────────────────────────────┘ │
│*│ │
│*│ ┌─[ References ]─────────────────────────────────────┐ │
│*│ │ Yates, James. "Tic Tac Toe Strategy Guide." │ │
│*│ │ Chess and Poker Dot Com. Accessed April 6, 2022. │ │
│*│ │https://www.chessandpoker.com/tic_tac_toe_strategy.html
│*│ └────────────────────────────────────────────────────┘ │
│*│ │
│*│ ┌─[ Search Terms ]───────────────────────────────────┐ │
│*│ │ tic-tac-toe, behavior; strategy; assertion checking│ │
│*│ └────────────────────────────────────────────────────┘ │
│*│ │
│*│ ┌─[ Instructions ]───────────────────────────────────┐ │
│*│ │ Run for Scope 1. │ │
│*│ ├─[ Run Statistics ]─────────────────────────────────┤ │
│*│ │ Scope 1: 5 traces in less than 1 sec. │ │
│*│ └────────────────────────────────────────────────────┘ │
└*┴───────────────────────────────────────────────────────*/
SCHEMA Tic_tac_toe;
/*
Explanation:
The 3x3 board with definitions for all cells:
Corner | Remnant | Corner
----------------------------
Remnant| Center | Remnant
----------------------------
Corner | Remnant | Corner
The center cell has 0-outer edges.
A remnant cell has 1-outer edge. ( corners are also edge cells )
A corner cell has 2-outer edges.
*/
ROOT Strategy_based_on_2nd_move_of_the_game:
(
choosing_remnant_next_to_X_on_2nd_move |/* Mistake, X wins */
choosing_remnant_NOT_beside_an_X_on_2nd_move |/* Mistake, X wins */
choosing_a_corner_on_2nd_move |/* Mistake, X wins */
choosing_center_on_2nd_Move_and_any_corner_on_4th_move |/* Mistake, X wins */
choosing_center_on_2nd_Move_and_any_remnant_on_4th_move /* No mistakes,Draw */
);
/* Player going second makes mistake on second move of the game */
choosing_remnant_next_to_X_on_2nd_move :
/* first move */ X_chooses_corner
/* second move - mistake */ O_chooses_remnant_next_to_X_on_first_turn
/* third move */ X_chooses_center
/* fourth move */ O_blocks_
/* fifth move */ X_chooses_corner_NOT_beside_any_O
/* sixth move */ O_blocks
/* seventh move */ X_wins;
/* Player going second makes mistake on second move of the game */
choosing_remnant_NOT_beside_an_X_on_2nd_move :
/* first move */ X_chooses_corner
/* second move - mistake */ O_chooses_remnant_NOT_beside_an_X_on_first_turn
/* third move */ X_chooses_center
/* fourth move */ O_blocks_
/* fifth move */ X_blocks
/* sixth move */ O_blocks
/* seventh move */ X_wins;
/* Player going second makes mistake on second move of the game */
choosing_a_corner_on_2nd_move :
/* first move */ X_chooses_corner
/* second move - mistake */ O_chooses_corner
/* third move */ X_chooses_any_corner
/* fourth move */ O_blocks_
/* fifth move */ X_chooses_last_corner
/* sixth move */ O_blocks_one_path
/* seventh move */ X_wins;
/* Player going second makes mistake on fourth move of the game */
choosing_center_on_2nd_Move_and_any_corner_on_4th_move :
/* first move */ X_chooses_corner
/* second move */ O_chooses_center
/* third move */ X_chooses_corner_opposite_previous_X
/* fourth move - mistake */ O_chooses_any_corner
/* fifth move */ X_blocks
/* sixth move */ O_blocks
/* seventh move */ X_wins;
/* No mistakes made by either player */
choosing_center_on_2nd_Move_and_any_remnant_on_4th_move :
/* first move */ X_chooses_corner
/* second move */ O_chooses_center
/* third move */ X_chooses_corner_opposite_previous_X
/* fourth move */ O_chooses_any_remnant
/* fifth move */ X_blocks
/* sixth move */ O_blocks
/* seventh move */ X_blocks
/* eighth move */ O_blocks
/* ninth move */ STALEMATE;
CHECK #X_wins == 1 OR #STALEMATE == 1
ONFAIL SAY ("X LOST!");
/*----------------COORDINATION SOLELY FOR VISUAL AID ___ */
/*NONE OF THIS COORDINATION CONSTRAINS OR INFLUENCES THE STRATEGY */
/* JUST VISUAL COMMENTARY FOR THE VIEWER */
COORDINATE $XEE_XEO: ( choosing_remnant_next_to_X_on_2nd_move |
choosing_remnant_NOT_beside_an_X_on_2nd_move )
DO
ADD SAY("O chooses a remnant on second move.") PRECEDES $XEE_XEO;
OD;
COORDINATE $XEE_XEO: choosing_a_corner_on_2nd_move
DO
ADD SAY("O chooses any corner on second move. ") PRECEDES $XEE_XEO;
OD;
COORDINATE $XOE: (
choosing_center_on_2nd_Move_and_any_corner_on_4th_move |
choosing_center_on_2nd_Move_and_any_remnant_on_4th_move
)
DO
ADD SAY("O chooses center on second move.") PRECEDES $XOE;
OD;
COORDINATE $first_move: X_chooses_corner
DO
ADD SAY("FIRST MOVE OF THE GAME.") PRECEDES $first_move;
OD;
COORDINATE $second_move:
(
O_chooses_remnant_next_to_X_on_first_turn |
O_chooses_remnant_NOT_beside_an_X_on_first_turn |
O_chooses_corner |
O_chooses_center
)
DO
ADD SAY("SECOND MOVE OF THE GAME.") PRECEDES $second_move;
OD;
COORDINATE $third_move:
(
X_chooses_center |
X_chooses_any_corner |
X_chooses_corner_opposite_previous_X
)
DO
ADD SAY("THIRD MOVE OF THE GAME.") PRECEDES $third_move;
OD;
COORDINATE $fourth_move:
( O_blocks_ | O_chooses_any_corner )
DO
ADD SAY("FOURTH MOVE OF THE GAME." ) PRECEDES $fourth_move;
ADD SAY("X is now guaranteed to win") PRECEDES $fourth_move;
OD;
COORDINATE $fourth_move: O_chooses_any_remnant
DO
ADD SAY("FOURTH MOVE OF THE GAME." ) PRECEDES $fourth_move;
ADD SAY("STALEMATE IS NOW GUARANTEED ") PRECEDES $fourth_move;
OD;
/******************************************************************/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment