TIC-TAC-TOE Introducing Expert Systems to Middle School Students ...

12 downloads 0 Views 335KB Size Report
game of X's and O's (tic-tac-toe). This simple game was selected because most middle school age students are already domain experts. The participant has to.
TIC-TAC-TOE Introducing to Middle School

Expert Students

Robert A. Pilgrim Dept. of Computer Science and Information Murray State University Murray, KY 42071 (502) 762-6220- RAPi@[email protected] Abstract Machines that play simple games have been a part of the development and promotion of computers for years. Charles Babbage conceived of a machine to play tic-tac-toe in an effort to obtain finding for his

Analytical C~e

Engine.

Systems

needed to play a perfect game of tic-tactoe, and the same rule base is valid whether the opponent or the computer makes the first move. 1. Introduction We offer a rule-based expert systems development program called TICTACTO as part of a week-long summer computer science workshop for Middle school students. The workshop introduces the participants to computer programming, graphics and animation, multimedia, computer architectures, networking and artflcial intelligence. We also tour other colleges in the university to show how the computer is used in business and industry.

1 As part of the Wor-

participants design and implement a rul; base for an expert system that plays the game of X’s and O’s (tic-tac-toe). This simple game was selected because most middle school age students are already domain experts. The participant has to select and order six or fewer rules with a seventh catch-all rule, “Take any available position.” The designers debug their own expert systems by playing the game and modifying their rule bases. Once they are satisfied with their own design, they play against each other’s systems in expert a round-robin tournament.

In earlier years we had noticed a problem with the presentation of some of the more abstract areas of computer science. In particular, our coverage of expert systems was dry compared to other computerrelated demonstrations such as those involving robots and computer-generated animations.

The development environment, written in Pascal to run under MS-DOS, displays the current state of the game board and lists the rules with the most recently “fwed” rule being highlighted. This program is far from a complete expert system, but it does illustrate a number of the principles of expert systems design.

We realized that to hold the attention of typical middle school students, we had to get them actively involved in the design of an expert system. Unfortunately, the learning curve for any practical expert system development tool is steep even for skilled professionals. Such packages are

Like most expert systems, a reasonable solution to the tic-tac-toe problem can be embodied in a surprisingly small rule No more than seven rules are base.

well beyond the capabilities workshop participants.

Permission to y without fee all or parl of this material is granted ptwided‘%t at the copies are not made or distributed for direct commercial advanta e, the ACM copyrtght notice and the title of the publication and L date appear, and notice is given that CO@ is by permission of the Association of Computing Machfnery. Y o copy otherwise, or to republish, requires a fee

andkws ecific

Systems

rmission.

SiGCSf?’95 &Nashville, TN USA 0 1995 ACM 0-89791 -693-)r/9WOO03,...$505O

340

TICTACTO

is our

functionality

and

compromise accessibility.

of

our

between A major

advantage of using the game of tic-tac-toe the participants are already is that

domain experts. The program provides an interactive environment in which the user can quickly cycle between rule base editing and performance testing. On the other hand, the program is hardwired for the game of tic-tac-toe and is limited to a single-level rule base (i.e. no meta-rules), 2

This game is ideally suited for a demonstration of an expert system because of it is simple and it can be tested quickly. It also lends itself to the rule base paradigm with rules that are easy to understand and methods that are easy to implement in a high-level language.

Before beginning the design exercise, the participants are given an overview and a brief history of expert systems and artificial intelligence (AI). Noyes provides an excellent reference source for the major

3. The TICTACTO Environment TICTACTO is a menu driven program divided into two major modules. The fwst module allows the user to create, edit and save a rule base for playing tic-tat-toe by selecting and ranking a set of rules in the desired order of fring. The second module allows the user to play the game of tic-tactoe against the computer. Computer moves are determined from the userdefmed rule base, which is continuously displayed while the game is played. The current rule being “freed” is highlighted so that the user can follow the decision making process. The same rule base is used whether the user or the computer makes the fwst move.

milestones

in AI. 3

Following

the

participants the

overview,

are asked

minimum

the

workshop

to make

a guess

of

of rules

needed

to

number

capture the knowledge toe player. Participants

of an expert tic-tacare usually very

surprised

that

seven

to discover

rules

tic-tac-toe

are

needed

no more

to play

than

a perfect

game.

Using the TICTACTO program, the typical middle school student can design a competent rule base in around 30 minutes. During the testing phase the instructor goes through the lab playing against the student’s rule bases. This activity quickly evolves into a competition to “beat the teacher.” Students tend

to

makes

work

“good”

opponent bases

initially well

moves.

makes

typically

build when

bases

the

However,

a “bad” make

rule

or three examples of bad usually sufficient to show the design flaws in a rule base.

Base Design

Module

candidate rules, shown in Table 1. The terminology used in the rules is defined in help screens.

ules for TIC TA!!

that

opponent when

move,

terrible

4. Rule

In the rule base design module, the user is asked to select six rules from a set of 12

these

moves. moves student

A. B. C. D. E. F, G. H.

Take center position Block three-in-a-row Make three-in-a-row Take corner next to an open side Take corner next to two open sides Take any corner Take corner opposite player corner If player has diagonal corners then take any side I. Take side with an open corner J. Take side with two open corners K. Take any side L. Take any position

the rule Two are any

2. The Game of TIC-TAC-TOE The game of tic-tac-toe is played on a 3 by 3 grid, onto which players take turns placing their marks (either an X or an O), with the goal of being the fwst player to get three of their marks in a straight line (horizontally, vertically or diagonally),

341

A collection of candidate rules were developed over a number of years by computer science students and the author as part of an algorithms course project. The 12 candidate rules selected for TICTACTOE were chosen for their relative simplicity.

obtained. When the user selects Done, TICTACTO automatically saves the rule base in a fde and returns to the main menu. A typical rule base is shown in Table below. This rule base works well only the opponent makes “good” moves.

The labeled tic-tac-toe game board shown in Figure 1 below should clarify most of this terminology. An open side is defined as an available side position. A corner with two open sides would, therefore, be a corner position for which neither adjacent side position is currently occupied. I I CORNER

I

SIDE

CORNER

SIDE

SIDE

SIDE

CORNER

TICTACTO

01)* R1. R2. R3. R4. R5. R6. R7.

[ CORNER

CENTER

.

2: ~

2 if

Take Make Block Take Take Take Take

center 3-in-a-row 3-in-a-row any corner corner next to an open side corner next to two open sides any available position

5. Game Playing Module When users first enter the game playing module they are asked if the computer is to make the fwst move. If so, the game board is displayed with the computer’s frost move already made. The current rule base is displayed underneath the game board with the active rule highlighted. This feature is important to show the user the logic of the rule base being tested. Figure 2 shows the sequence of moves for a typical game using the rule base shown in Table 2 above. In this game, the opponent (0) makes the fwst move. When the opponent makes what seems to be reason-able moves, the rule base plays a good game of tic-tac-toe.

I Bod

First, the user is prompted to choose a rank and then to select a rule to be placed at that rank. Any rule can be changed at any time and the rules can be entered in any order. The maximum number of userselected rules is six. The seventh rule cannot be changed or removed. It states, “Take any available position” and results in a random selection of one of the unoccupied board positions. This rule is used to ensure that the computer will always make some move, even if none of the user-selected rules can free.

Ql–l– _l_l _ II

The fact that a subset of six of these rules is stilcient to play a perfect game of tictae-tee has been demcnwtrated by an exhaustive traversal of the game tree. It is not implied that this rule set is unique or minimal.

by

QIQl _ _lxl _ II

RI

QILLlx -Lxl01 I by R3

The user continues to select and rank rules until the desired rule base is

Ql–l– _lxl _ II

by

QQ.1.x -.kl01 I

M

342

QIQIX _lxl _ II

R3

QIQlz 2LJxJ-

LuQlx x.lxlQ

01

I

01 lx

by

R4

od” Move&

The same rule base does not perform so well when the opponent makes a “bad” move, see Figure 3.

Q1–1– _l_l _ II

L21-l– _lxl _ II

Ql_l _ _lxl _ I 10 by

RI

xl by

10 R4

10

xl by

3

5

7

II

,,bad,,

This pattern can be used to simpli.& the implementation of the rules listed in Table 1 in the following manner. Let each player build a list of the digits 1 through 9 whose positions in this puzzle correspond to moves made in tic-tac-toe. With this correspondence established, the task of looking for a way of making three-in-a-row becomes a search for an unused digit, which when combined with a pair of cligits already held, sums to 15. The implementations of several of the c)ther rules in TICTACTO were made easier using this analogy. This is an example of the transformation of pattern matching problems into arithmetic problems, which more readily lend themselves to computer solution.

10 R3

With a little practice the instructor can become familiar with these “bad” move sequences and apply them to student rule bases as a teaching tool. 6. Implementation Details As with any software package that provides a simple interface for the user, TICTACTO was a tedious program to write. The majority of the complexity of implementing the rules has been hidden born the user. As noted by Townsend and Feucht, the most d~lcult problem in the implementation of an expert system in the conversion of the knowledge into a form that can be used by the computer effectively and still be understood by the

7. Recommendations The incorporation of TICTACTO in the Summer Computer Science Workshop solved the problem of a dry presentation of an abstract subject, by replacing it with a creative activity involving a specific task. While this approach greatly reduced the scope of the presentation, it was ]more compatible with the interests and abilities of middle school age students. Placing the student in the role of the computer is an application of Piaget’s “egocentrism” in the Formal Operations

Anyone considering a similar user. 4 exercise is advised to spend some time devising as many labor-saving mechanisms as possible. One such mechanism applicable to tic-tac-toe is provided here as an example. Consider the following puzzle goal is to distribute the digits in a 3 by 3 grid so that every digits sums to 15 (horizontally, and diagonally). One solution

6

41912

QIQIQ _lXIX

xl

1

I

Ql–l– _lxl _ xl 10 move

Ql_lQQl_lQ _lX.l__lXUi

8

period

(ages 11-15 years).5

We wish

in which the 1 through 9 line of three vertically is,

between

to point rule

out that

bases

design exercise enthusiasm. This fact ended

that

interesting

343

most

in ties.

which

the competition followed

the

met with mixed was partly due to the

of the

tournament

games

It also seemed to be less for the students to have two

$

computers playing each other than when they had their programs play against a Their favorite part of human opponent. the exercise was having their programs beat (or at least tie) the instructor. A listing of the Pascal Source code for TICTACTO is available from the author, upon request. For an electronic copy of the executable and source code, contact the author via e-mail. References 1.

Spencer,

Donald

c~

D., ~ pp. 263-268,

Spartan

, New York,’ 1968. 2.

Keller, Robert, w: Dev~

p. 153, Yourden 1987.

Exnert

Svsteu . . Ann*

Press Computing

Series;

3. Noyes, James L., “Teaching AI: A Breadth-First Approach”, SIGC!SE Bulletin, Twenty-Fourth SIGCSE Technical Symposium on Computer Science Education, Vol. 25, No, 1, pp. 33-37, March, 1993. 4. Townsend, Carl and Dennis Feucht, Personal ~min~ and Proms m-min~ &ert Svs@IM, p. 23, TAB Books Blue Ridge Summit, PA, 1986. 5.

Phillips,

H. Freeman

Inc.,

John

L. Jr., The Or~ Theqry pp. 131-32, W. and Co., 197;.

344