1 / 14

AI – Week 10 AI and Games (2)

AI – Week 10 AI and Games (2). Lee McCluskey, room 2/09 Email lee@hud.ac.uk http://scom.hud.ac.uk/scomtlm/cha2555/. Last Week. Introduction to AI Games 2- player games Minimax and alpha beta pruning. AI in Games: practical example.

LeeJohn
Download Presentation

AI – Week 10 AI and Games (2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AI – Week 10AI and Games (2) Lee McCluskey, room 2/09 Email lee@hud.ac.uk http://scom.hud.ac.uk/scomtlm/cha2555/

  2. Last Week Introduction to AI Games 2- player games Minimax and alpha beta pruning

  3. AI in Games: practical example This week and next week we will implement a 2-player board game in Prolog. • Board (state) representation • Board (state) evaluation • Move application • Move generation • Mini-max / alpha beta algorithm Same Code in Prolog

  4. Fox and Goose fox Goal: Goose in column 4 HOME Rules: If fox next to goose and foxes turn, then fox can eat goose Fox/goose can move diagonal as well as vert/horiz. Only ONE fox can move each turn. goose fox

  5. Fox and Goose fox Goal: Goose in column 4 HOME Rules: If fox next to goose and foxes turn, then fox can eat goose Fox/goose can move diagonal as well as vert/horiz goose fox GOOSE to move – which MOVE??????

  6. Fox and Goose fox Goal: Goose in column 4 HOME Rules: If fox next to goose and foxes turn, then fox can eat goose Fox/goose can move diagonal as well as vert/horiz goose fox FOX to move – which MOVE??????

  7. Fox and Goose – more elaborate game.. Goal: Goose in last column Rules: If fox next to goose and foxes turn, then fox can eat goose Fox/goose can move diagonal as well as vert/horiz New rules: -Fox can’t move to last column -Obstacles to reduce movement fox HOME fox goose

  8. Board (state) Representation There are MANY ways to represent the state of a game eg b(1,[ 0 , 0, f, 0 ],       [ 0 , 0, 0, 0 ],       [ 0 , 0, 0, 0 ],       [ g , 0, 0, 0 ],       [ 0 , 0, 0, 0 ],       [ 0 , 0, f, 0 ]).

  9. Better Representation b(1, [ x(1,1,0), x(1,2,0), x(1,3,f), x(1,4,0), x(2,1,0), x(2,2,0), x(2,3,0), x(2,4,0), x(3,1,0), x(3,2,0), x(3,3,0), x(3,4,0), x(4,1,g), x(4,2,0), x(4,3,0), x(4,4,0), x(5,1,0), x(5,2,0), x(5,3,0), x(5,4,0), x(6,1,0), x(6,2,0), x(6,3,f), x(6,4,0)]). ORDER OF ELEMENT IN LIST IS IRRELEVANT

  10. Representation and Simple Evaluation b(1, [ x(1,1,0), x(1,2,0), x(1,3,f), x(1,4,0), x(2,1,0), x(2,2,0), x(2,3,0), x(2,4,0), x(3,1,0), x(3,2,0), x(3,3,0), x(3,4,0), x(4,1,g), x(4,2,0), x(4,3,0), x(4,4,0), x(5,1,0), x(5,2,0), x(5,3,0), x(5,4,0), x(6,1,0), x(6,2,0), x(6,3,f), x(6,4,0)]). /* SIMPLE EVALUATION – Positive for Goose, Negative for Fox */ board_eval(L, 10000) :- member(x(_,4,g), L),!. board_eval(L, -10000) :- \+ member(x(_,_,g), L),!. board_eval(L, 0 ) :- !.

  11. Move Application AND Generation apply( FROM, TO, BOARD_IN, BOARD_OUT) Move Generation: Precondition: FROM and BOARD_IN are instantiated. Postcondition: TO and BOARD_OUT get values. Move Application: Precondition: FROM, TO, and BOARD_IN are instantiated. Postcondition: BOARD_OUT gets a value.

  12. Move Application AND Generation Fixes parameters % Assume Z is either f or g apply( x(X,Y,Z), x(X1,Y1,Z1), B_IN, B_OUT) :- % move to empty square OR fox eats goose .. (Z1 = 0 ; (Z=f, Z1=g)), member(x(X,Y,Z), B_IN), member(x(X1,Y1,Z1),B_IN), % FOX can't go into the fourth column... \+ (Z=f, Y1=4), % two squares must be next to each other next(X,Y,X1,Y1), % checks over – now make the move remove(x(X,Y,Z), B_IN, B1), remove(x(X1,Y1,Z1), B1, B2), B_OUT = [x(X1,Y1,Z),x(X,Y,0)|B2]. Generates Generate and Test Tests parameters Deterministic procedures – only one possible output

  13. Search depth Identifier of the starting board Examples Who goes first Initial call to minimax Finds best move | ?- t(7,5,goose). Move goose from 4,1 to 5,1 Estimated value of Board is -5 unclear who wins Number of leaf boards evaluated is 43979 Move fox from 3,3 to 4,2 Move goose from 5,1 to 6,1 Move fox from 4,2 to 5,1 Move goose from 6,1 to 7,2 Move fox from 5,1 to 6,1 Move goose from 7,2 to 7,3 yes - not enough search space to see who wins so fox chases goose Subsequent calls to Minimax from “finish_game” procedure

  14. Examples | ?- t(8,5,goose). Move goose from 4,1 to 5,1 Estimated value of Board is 10000 goose wins Number of leaf boards evaluated is 222714 Move fox from 3,3 to 2,2 Move goose from 5,1 to 4,2 Move fox from 2,2 to 3,3 Move goose from 4,2 to 5,3 Move fox from 3,3 to 4,2 Move goose from 5,3 to 4,4 Move fox from 4,2 to 5,3 yes | ?- • This time enough search space to see that the goose wins • Note the fox wanders about as it knows that no win is possible!

More Related