Farsi / Persian
NetLogo User Community Models
WHAT IS IT?
This model is a Netlogo version of the classic Milton Bradley/Hasbro game "Connect Four: The Vertical Four-in-a-Row Checkers Game." It is intended to be a two-player game, and is entirely for fun!
The rules are simple. Each player places a colored-checker in one of the seven slots. The first player to get four in a row, column, or on a diagonal wins.
HOW IT WORKS
SETUP creates the game board, with seven columns and six rows. The grey space at the top of the screen is necessary because Netlogo's graphic canvas won't permit the exact dimensions of the game space. The white "holes" are turtles that serve as place-holders for the colored checkers. They have no other function in the game.
ADD-PIECE [x] is called by the seven buttons on the bottom of the screen. They are used by the players to add each checker to the board. ADD-PIECE [x] finds the first "empty" space in the relevant column, and inserts a checker of the player's color. This procedure uses a list to evaluate possible y coordinates to find the first empty space in a column. Once placed on the board, the new turtle sets its color to that of the player, and uses SET-POSSIBLE-HEADINGS to set its own list of possible headings for evaluating each move.
CHECK-FOR-WINNER is only run after seven moves have been completed. This procedure uses the two lists (single-headings and double-headings) to look in each of the legal directions to determine if the most recently-played checker has won the game. The procedure looks first to see if the latest piece is at the end of a chain of 4 like-checkers (single-headings), and then looks to see if it is inside (not on the end) of a string of four checkers. This analysis involves looking forward two checkers on a heading, and then "turning around" (by adding 180 degrees to the heading) to look at the two checkers in the opposite direction.
When the game is over, the command window prints which side won, and in how many steps.
To play again, either use the "PLAY AGAIN?" button (calling SETUP), or hit any one of the seven button on the bottom of the screen.
HOW TO USE IT
It's pretty self-explanatory. Find a friend, and start seeing who can win the game first. Its the 1970's version of outwit, outlast, and outplay!
THINGS TO NOTICE
The code for this model is remarkably short, with just three meaningful procedures. (STARTUP loads the model but isn't necessary).
The game will only run under Netlogo 2.0 and later because of its reliance on the "ask patch-at-heading-and-distance" primitive.
The model is not really "agent-based" in the traditional sense of the word, but it illustrates the robustness of the Netlogo environment and its ease of use. And it is just plain fun to play!
EXTENDING THE MODEL
One possible extension would be to build a procedure that would provide a "Help" mode - either pointing out existing patterns of three like-checkers or warning when a player is
Another extension would be to have the checkers appear at the top of the screen, and then "drop" into place in each column.
A one-player version of the game (with a computer opponent) is probably the most challenging extension to the model, and would certainly take longer than the initial model to code, but it would be an amazing accomplishment!
This model is related to the game models in the Netlogo Models Library. Unlike Frogger and Pac-Man, which require the awkward use of buttons to replicate the original joysticks, CONNECT FOUR plays completely like the original - with the one exception of having the ability to make all the checkers drop to the table.
CREDITS AND REFERENCES
This model was inspired by the Hasbro game "CONNECT FOUR" and is dedicated to Nicholas Gizzi, an enthusiastic six year-old who is fascinated by the original Connect Four, and is now learning to move virtual turtles around a computer screen! He dutifully beta-tested this model.
The model was created by Michael C. Gizzi with assistance from Boyce Baker and Richard Vail. The model is copyright 2003 by the Center for Agent-Based Modeling, Mesa State College, 2508 Blichman Avenue, Grand Junction, CO 81505. http://www.modelingcomplexity.org.
The original board game CONNECT FOUR is copyright Hasbro 1998.
THE MODEL IS INTENDED SOLELY FOR EDUCATIONAL AND ENTERTAINMENT PURPOSES. IT MAY NOT BE REPRODUCED FOR COMMERCIAL USE WITHOUT VIOLATING EITHER OF THE COPYRIGHTS LISTED HERE.
NOTES ON connect4 and CONNIE
I have added a different CHECK-FOR-WINNER procedure; also CONNIE who plays a fair game,
CONNIE exhibits no intelligence, in fact a large proportion of her play is random because this avoids some of the repetition of machine play. Also it was discovered that the spatial relations of the game demand very complicated procedures to provide a greater level of play. The prime reason for this is the ease with which twofold, threefold, etc lines of 3 with common members can be formed and the extreme difficulty of anticipating the formation.
The Procedures section includes detailed explanations of the code and some of its working can be viewed in the Command Center.
Derek Rush who can be contacted on firstname.lastname@example.org February 2004.
(back to the NetLogo User Community Models)