|
65 | 65 | ; first created at the outset of each side's move based upon the chessboard list. |
66 | 66 | ; |
67 | 67 | ; Possible moves are evaluated by rapidly adding and removing these 'square' atoms. As a design |
68 | | -; consideration use of such atoms harmonizes well with the 'atomic' structure of Metta which is |
| 68 | +; consideration use of such atoms harmonizes well with the 'atomic' structure of MeTTa which is |
69 | 69 | ; not really the same as LISP type list processing. At the start of the move, the transient 'square' atoms |
70 | 70 | ; are loaded into atomspace and at the conclusion of the move the 'square' atoms are used to |
71 | 71 | ; recreate the chessboard. Take care that after "envisioning" moves you move the 'square' atoms |
|
81 | 81 | ; |
82 | 82 | ; During programming tail recursion functions were often created, but it was discovered that these |
83 | 83 | ; were often faster instead using metta calls to 'match'. The original functions have sometimes been retained for |
84 | | -; comparison. In general the defining features of Metta are the use of atomspace, 'match' 'superpose' and |
| 84 | +; comparison. In general the defining features of MeTTa are the use of atomspace, 'match' 'superpose' and |
85 | 85 | ; 'collapse'. Occasionally it is wise to use 'xor' in lieu of 'or' (if possible) to avoid unexpected |
86 | 86 | ; nondeterministic behavior. In general it is not necessary to think in GOFAI chaining terms (forward, backward). |
87 | 87 | ; |
|
1353 | 1353 | (match &self (square $x1 $y1 g $AI_rank) |
1354 | 1354 | ; if piece under threat by human |
1355 | 1355 | (if (== (take_dest ($x1 $y1) s) True) |
| 1356 | + ; if square not covered by a different AI piece that could in turn capture attacking human piece, |
| 1357 | + (if (xor (== (take_dest ($x1 $y1) g) False) |
| 1358 | + ; except if threatened piece is a queen. If queen is threatened play defense regardless... |
| 1359 | + (and (== (take_dest ($x1 $y1) g) True) (== $AI_rank q))) |
1356 | 1360 | ; find all empty squares to flee to... |
1357 | 1361 | (match &self (square $x2 $y2) |
1358 | 1362 | ; if piece can escape to an empty square |
|
1374 | 1378 | (empty) |
1375 | 1379 | ) |
1376 | 1380 | ) |
1377 | | - ))) |
| 1381 | + (empty))))) |
| 1382 | + |
| 1383 | +; This variation will play defense if high ranking pieces are ever threatened by a pawn. |
| 1384 | +(= (playdefense_match $AI_rank) |
| 1385 | + ; find all AI pieces |
| 1386 | + (match &self (square $x1 $y1 g $AI_rank) |
| 1387 | + ; find human pawns... |
| 1388 | + (match &self (square $PAWNx1 $PAWNy1 s p) |
| 1389 | + ; if there is a capture route for the human pawn to capture higher rank AI piece |
| 1390 | + (if (== (clear_route ($PAWNx1 $PAWNy1 s p) ($x1 $y1)) True) |
| 1391 | + ; find all empty squares to flee to... |
| 1392 | + (match &self (square $x2 $y2) |
| 1393 | + ; if piece can escape to an empty square |
| 1394 | + (if (== (clear_route ($x1 $y1 g $AI_rank) ($x2 $y2)) True) |
| 1395 | + ; if AI piece is not exposed in new position |
| 1396 | + (let* |
| 1397 | + ( ;envision the move to empty square, see if exposed after moves |
| 1398 | + ($__1 (move_piece ($x1 $y1 g $AI_rank) ($x2 $y2))) |
| 1399 | + ($exposed (take_dest ($x2 $y2) s)) |
| 1400 | + ; make sure king safe |
| 1401 | + ($king_status (checkking g)) |
| 1402 | + ($__2 (reset_pieces ($x1 $y1 g $AI_rank) ($x2 $y2))) |
| 1403 | + ) |
| 1404 | + (if (and (== $exposed False) (== $king_status False)) |
| 1405 | + ; success! |
| 1406 | + (($x1 $y1 g $AI_rank) ($x2 $y2)) |
| 1407 | + ; whoops, the piece is exposed to capture |
| 1408 | + (empty))) |
| 1409 | + (empty) |
| 1410 | + ) |
| 1411 | + ) |
| 1412 | + (empty))))) |
1378 | 1413 |
|
1379 | 1414 | ;************************************************************************* |
1380 | 1415 | ; Function: takehighestopen_scored |
|
2552 | 2587 | (progn |
2553 | 2588 | ; Retrieve the source box details. |
2554 | 2589 | (let $h (return_entire_box $f) ()) |
| 2590 | + ; Get source box color, assign NIL if no piece |
| 2591 | + (let $source_color (if (== (size-atom $h) 4) (nth 3 $h) NIL) ()) |
2555 | 2592 | ; Retrieve the destination box details. |
2556 | 2593 | (let $i (return_entire_box $g) ()) |
2557 | 2594 | (let $dest_color (if (== (size-atom $i) 4) |
2558 | 2595 | (nth 3 $i) |
2559 | 2596 | NIL) ()) |
2560 | | - ; Check there is a piece to move. |
2561 | | - (if (and (== (size-atom $h) 4) |
| 2597 | + ; Check there is a human piece to move. |
| 2598 | + (if (and (== $source_color s) |
2562 | 2599 | (xor |
2563 | 2600 | ; OK to move to open square size 2... |
2564 | 2601 | (== (size-atom $i) 2) |
|
0 commit comments