;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; RECOGNIZE_PLAYER_WIN_LHS ; ; FILE NAME: RECOGNIZE_PLAYER_WIN_LHS.LSP ; CREATION DATE: 11/17/89 ; AUTHOR: Frederick S. Schebor ; REVISIONS: ; Date Initials Reason for Revision ; PURPOSE: A left-hand-side knowledge source for triggering a right-hand-side knowledge source which will recognize a winning ; conditon on a tic-tac-toe board. ; METHOD: If blackboard conditions are right, pass the tic-tac-toe board on to DETECT_WIN. ; DECLARATION: parameter type I/O purpose ; --------- ---- --- ------- ; DEFUN recognize_player_win_lhs ( No passed parameters ; ) ; REFERENCED ROUTINES: ; detect_win ; get_blackboard_data ; lib$signal ; send_agenda_response ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( DEFINE-EXTERNAL-ROUTINE ( get_blackboard_data :FILE "SHAREABLE_BLACKBOARD_UTILITIES" :TYPE-CHECK T ) ( logical_name :LISP-TYPE STRING ) ( equivalence_name :LISP-TYPE STRING :ACCESS :IN-OUT ) ( number_of_characters :LISP-TYPE INTEGER :VAX-TYPE :WORD :ACCESS :IN-OUT ) ( return_status :LISP-TYPE INTEGER :ACCESS :IN-OUT ) ) ( DEFINE-EXTERNAL-ROUTINE ( lib$signal :FILE "LIBRTL" :TYPE-CHECK T ) ( condition_value :LISP-TYPE INTEGER ) ) ( DEFINE-EXTERNAL-ROUTINE ( send_agenda_response :FILE "SHAREABLE_BLACKBOARD_UTILITIES" :TYPE-CHECK T ) ( rhs_routine_name :LISP-TYPE STRING ) ( number_conditions_satisfied :LISP-TYPE INTEGER :VAX-TYPE :WORD ) ( cpu_time_seconds :LISP-TYPE SINGLE-FLOAT ) ( certainty_of_result :LISP-TYPE SINGLE-FLOAT ) ( return_status :LISP-TYPE INTEGER :ACCESS :IN-OUT ) ) ( DEFUN recognize_player_win_lhs ( ) ( SETF blackboard_data " " ) ( SETF return_status 0 ) ( SETF number_of_characters 0 ) ( SETF ttt_board " " ) ( CALL-OUT get_blackboard_data "BLACKBOARD_STATUS" blackboard_data number_of_characters return_status ) ( COND ( ( NOT ( EQUAL return_status 1 ) ) ( CALL-OUT lib_signal return_status ) ) ( ( STRING-EQUAL blackboard_data "RUNNING" :end1 number_of_characters ) ;Blackboard RUNNING? ( CALL-OUT get_blackboard_data "GAME_STATUS" blackboard_data number_of_characters return_status ) ( COND ( ( NOT ( EQUAL return_status 1 ) ) ( CALL-OUT lib_signal return_status ) ) ( ( STRING-EQUAL blackboard_data "DISPLAY_BOARD" :end1 number_of_characters ) ;Status DISPLAY_BOARD? ( CALL-OUT get_blackboard_data "TTT_BOARD" ttt_board number_of_characters return_status ) ( COND ( ( NOT ( EQUAL return_status 1 ) ) ( CALL-OUT lib_signal return_status ) ) ( ( detect_win ttt_board ) ;Check for win ( CALL-OUT send_agenda_response "RECOGNIZE_PLAYER_WIN_RHS" 5 0.01 99.9 return_status ) ;Send ) ) ) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; DETECT_WIN ; ; FILE NAME: RECOGNIZE_PLAYER_WIN_LHS.LSP ; CREATION DATE: 11/17/89 ; AUTHOR: Frederick S. Schebor ; REVISIONS: ; Date Initials Reason for Revision ; PURPOSE: Given a tic-tac-toe board (string of 9 characters), see if a winning condition exists. ; METHOD: Pass character triads for each possible win condition to CHECK_WIN. If CHECK_WIN returns non NIL, then a winning ; conditon exists. ; DECLARATION: parameter type I/O purpose ; --------- ---- --- ------- ; DEFUN detect_win ( board STRING I the tic-tac-toe board ; ) ; REFERENCED ROUTINES: ; check_win ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( DEFUN detect_win ( board ) ( OR ( check_win board 0 1 2 ) ( check_win board 3 4 5 ) ( check_win board 6 7 8 ) ( check_win board 0 3 6 ) ( check_win board 1 4 7 ) ( check_win board 2 5 8 ) ( check_win board 0 4 8 ) ( check_win board 2 4 6 ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; CHECK_WIN ; ; FILE NAME: RECOGNIZE_PLAYER_WIN_LHS.LSP ; CREATION DATE: 11/17/89 ; AUTHOR: Frederick S. Schebor ; REVISIONS: ; Date Initials Reason for Revision ; PURPOSE: Check for a winning condition on a tic-tac-toe board. ; METHOD: Given a tic-tac-toe board as a string and three indices, return TRUE if the characters at the indeces are equal and ; not equal to a ' '. ; DECLARATION: parameter type I/O purpose ; --------- ---- --- ------- ; DEFUN check_win ( board STRING I the tic-tac-toe board ; index_1, _2, _3 INTEGER I the indices ; ) ; REFERENCED ROUTINES: ; None ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( DEFUN check_win ( board index_1 index_2 index_3 ) ( AND ( EQUAL ( CHAR board index_1 ) ( CHAR board index_2 ) ) ( EQUAL ( CHAR board index_2 ) ( CHAR board index_3 ) ) ( CHAR/= ( CHAR board index_2 ) #\SPACE ) ) )