Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence and Robotics By Keith Bright & John DeBovis.

Similar presentations


Presentation on theme: "Artificial Intelligence and Robotics By Keith Bright & John DeBovis."— Presentation transcript:

1 Artificial Intelligence and Robotics By Keith Bright & John DeBovis

2 Progress Switched from ELIZA chat program to Tic Tac Toe program Switched from ELIZA chat program to Tic Tac Toe program Spent time developing Tic Tac Toe program Spent time developing Tic Tac Toe program Two dimensional arrayTwo dimensional array Human vs. ComputerHuman vs. Computer Use test to decide what is the smartest decision for the computer to make—becoming an example of weak intelligenceUse test to decide what is the smartest decision for the computer to make—becoming an example of weak intelligence

3 Main #define ROW 3 #define COL 3 #define SPACE ‘ ' void get_computer_move(char tic[][COL]); void get_player_move(char tic[][COL]); void disp_tic(char tic[][COL]); int check(char tic[][COL]); int main(){ int main(){ char tic[ROW][COL]={' '}; char tic[ROW][COL]={' '}; char done= SPACE; char done= SPACE; while(done==SPACE){ while(done==SPACE){ disp_tic(tic); disp_tic(tic); get_player_move(tic); get_player_move(tic); done=check(tic); done=check(tic); get_computer_move(tic); get_computer_move(tic); done=check(tic); done=check(tic); }if(done=='X'){ printf("You Win!.\n"); printf("You Win!.\n"); } else{ else{ printf("I Won!!!!!\n"); printf("I Won!!!!!\n");}disp_tic(tic);}

4 Get Players Move /*Input Players move*/ void get_player_move(char tic[ROW][COL]{ int i=0,j=0; printf("Enter coordinates for your X, with the index starting at 0: "); scanf("%d %d", &i,&j; if(tic[i][j]!=SPACE){ printf("Invalid move, try again. \n"); get_player_move(tic);}else{tic[i][j]='X';}}

5 Get Computer Move /*Get the computer's move*/ void get_computer_move(char tic[][COL]); Problems Problems We had trouble figuring out where to insert the computer’s next moveWe had trouble figuring out where to insert the computer’s next move In order to do so, the computer must test to see where the smartest move would beIn order to do so, the computer must test to see where the smartest move would be

6 Display Game /*Display the game board*/ void disp_tic(char tic[][COL]){ int t; for(t=0; t<3;t++){ printf("%c | %c | %c", tic[t][0], tic[t][1], tic[t][2]); if(t!=2){printf("\n---|---|---\n");}}printf("/n");}

7 Test for Winner /*See if there is a winner*/ int check(char tic[][COL]){ int j; char answer = SPACE; int k=0; int i=2; for(j=0;j<3 && answer==SPACE;j++){ if(tic[j][0]==tic[j][1] && tic[j][1]==tic[j][2]){ answer=tic[j][0]; return (answer); }} for(j=0; j<3 && answer==SPACE;j++){ if(tic[0][j]==tic[1][j] && tic[1][j]==tic[2][j]){ answer=tic[0][j]; return answer; }}

8 Test for Winner (cont.) /*test diagonal*/ if(tic[k][k]==tic[k+1][k+1] && tic[k+1][k+1]==tic[k+2][k+2]){ return (tic[j][j]); } else if(tic[k][i]==tic[k+1][i-1] && tic[k+1][i-1]==tic[i][k]){ return (tic[i][j]); } return SPACE; }


Download ppt "Artificial Intelligence and Robotics By Keith Bright & John DeBovis."

Similar presentations


Ads by Google