130 likes | 255 Views
Introduction to Robotics ENTC 4287-001 Project Presentation Tic-Tac-Toe Game (Seiko robot) For Professor Guanghsu A. Chang Robotics Instructor East Tennessee State University Johnson City, Tennessee By Group #1 Garth R. Ghearing Bethanne S. Townsend. The Setup:.
E N D
Introduction to Robotics ENTC 4287-001 Project Presentation Tic-Tac-Toe Game (Seiko robot) For Professor Guanghsu A. Chang Robotics Instructor East Tennessee State University Johnson City, Tennessee By Group #1 Garth R. Ghearing Bethanne S. Townsend
The Setup: Dimensioning variables and palettes Declaring message box statements Function main Integer increm, sit, answer, zaq, qaz, hwin, cwin, nowin, wohs String at1$, at2$, at3$, at4$, at5$, at6$, at7$, at8$, at9$, allat$, msg1$, title$, you$, me$, tie$, show$, wosh$ Power High Speed 100 SpeedS 30 Palet1 P1, P2, P1, 5, 1 Palet2 P3, P4, P5, 3, 3 msg1$ = "If you want to go first, hit YES" + Chr$(13) + Chr$(10) msg1$ = msg1$ + "Otherwise, hit NO" you$ = "You won!" + Chr$(13) + Chr$(10) you$ = you$ + "Please reset your pieces after I do." me$ = "I won!" + Chr$(13) + Chr$(10) me$ = me$ + "Please reset your pieces after I do." tie$ = "It's a draw." + Chr$(13) + Chr$(10) tie$ = tie$ + "Please reset your pieces after I do." title$ = "Tic Tac Toe"
Initializing: Clearing used variables Determining play order Scoreboard Human:0 Robot:0 Draw:0 start: where = 0 increm = 1 at1$ = "0" at2$ = "0" at3$ = "0" at4$ = "0" at5$ = "0" at6$ = "0" at7$ = "0" at8$ = "0" at9$ = "0" ClrScr Print " Scoreboard" Print "Human:", hwin, " Robot:", cwin, " Draw:", nowin MsgBox msg1$, 3, title$, answer If answer = 6 Then GoTo turn If answer = 7 Then GoTo moves If answer = 2 Then Goto endit
Human's Turn: Determining where and when the human places a piece turn: If at1$ = "0" Then If Sw(1) = 1 Then at1$ = "1"; Goto moves EndIf If at2$ = "0" Then If Sw(2) = 1 Then at2$ = "1"; Goto moves EndIf If at3$ = "0" Then If Sw(3) = 1 Then at3$ = "1"; Goto moves EndIf If at4$ = "0" Then If Sw(4) = 1 Then at4$ = "1"; Goto moves EndIf If at5$ = "0" Then If Sw(5) = 1 Then at5$ = "1"; Goto moves EndIf If at6$ = "0" Then If Sw(6) = 1 Then at6$ = "1"; Goto moves EndIf If at7$ = "0" Then If Sw(7) = 1 Then at7$ = "1"; Goto moves EndIf If at8$ = "0" Then If Sw(8) = 1 Then at8$ = "1"; Goto moves EndIf If at9$ = "0" Then If Sw(9) = 1 Then at9$ = "1"; Goto moves EndIf Goto turn
The isitover subroutine (part1): Showing the score and piece placement isitover: ClrScr Print " Scoreboard" Print "Human:", hwin, " Robot:", cwin, " Draw:", nowin wosh$ = "" For wohs = 1 To 3 If wohs = 1 Then show$ = at7$ If wohs = 2 Then show$ = at8$ If wohs = 3 Then show$ = at9$ If show$ = "4" Then wosh$ = wosh$ + "C" If show$ = "1" Then wosh$ = wosh$ + "H" If show$ = "0" Then wosh$ = wosh$ + "-" Next wohs Print wosh$ wosh$ = "" For wohs = 1 To 3 If wohs = 1 Then show$ = at4$ If wohs = 2 Then show$ = at5$ If wohs = 3 Then show$ = at6$ If show$ = "4" Then wosh$ = wosh$ + "C" If show$ = "1" Then wosh$ = wosh$ + "H" If show$ = "0" Then wosh$ = wosh$ + "-" Next wohs Print wosh$ wosh$ = "" For wohs = 1 To 3 If wohs = 1 Then show$ = at1$ If wohs = 2 Then show$ = at2$ If wohs = 3 Then show$ = at3$ If show$ = "4" Then wosh$ = wosh$ + "C" If show$ = "1" Then wosh$ = wosh$ + "H" If show$ = "0" Then wosh$ = wosh$ + "-" Next wohs Print wosh$ Scoreboard Human:0 Robot:0 Draw:0 _CH CH_ C_H
The isitover subroutine (part2): Determining if the game is over If at1$ + at2$ + at3$ = "111" Then GoTo youwin If at1$ + at4$ + at7$ = "111" Then GoTo youwin If at1$ + at5$ + at9$ = "111" Then GoTo youwin If at4$ + at5$ + at6$ = "111" Then GoTo youwin If at7$ + at8$ + at9$ = "111" Then GoTo youwin If at7$ + at5$ + at3$ = "111" Then GoTo youwin If at2$ + at5$ + at8$ = "111" Then GoTo youwin If at3$ + at6$ + at9$ = "111" Then GoTo youwin If at1$ + at2$ + at3$ = "444" Then GoTo iwin If at1$ + at4$ + at7$ = "444" Then GoTo iwin If at1$ + at5$ + at9$ = "444" Then GoTo iwin If at4$ + at5$ + at6$ = "444" Then GoTo iwin If at7$ + at8$ + at9$ = "444" Then GoTo iwin If at7$ + at5$ + at3$ = "444" Then GoTo iwin If at2$ + at5$ + at8$ = "444" Then GoTo iwin If at3$ + at6$ + at9$ = "444" Then GoTo iwin allat$ = at1$ + at2$ + at3$ + at4$ + at5$ + at6$ + at7$ + at8$ + at9$ If allat$ <> "0" Then Return Else GoTo draw EndIf
Determining the appropriate move for the robot: Can it win / if not can you win / if not can it build to a win / if not then it just places a piece moves: GoSub isitover For zaq = 1 To 3 If zaq = 1 Then qaz = 8 If zaq = 2 Then qaz = 2 If zaq = 3 Then qaz = 4 If Val(at1$) + Val(at2$) + Val(at3$) = qaz Then If at1$ = "0" Then sit = 1; at1$ = "4"; GoTo place If at2$ = "0" Then sit = 2; at2$ = "4"; GoTo place If at3$ = "0" Then sit = 3; at3$ = "4"; GoTo place EndIf If Val(at1$) + Val(at4$) + Val(at7$) = qaz Then If at1$ = "0" Then sit = 1; at1$ = "4"; GoTo place If at4$ = "0" Then sit = 4; at4$ = "4"; GoTo place If at7$ = "0" Then sit = 7; at7$ = "4"; GoTo place EndIf If Val(at1$) + Val(at5$) + Val(at9$) = qaz Then If at1$ = "0" Then sit = 1; at1$ = "4"; GoTo place If at5$ = "0" Then sit = 5; at5$ = "4"; GoTo place If at9$ = "0" Then sit = 9; at9$ = "4"; GoTo place EndIf If Val(at4$) + Val(at5$) + Val(at6$) = qaz Then If at4$ = "0" Then sit = 4; at1$ = "4"; GoTo place If at5$ = "0" Then sit = 5; at1$ = "4"; GoTo place If at6$ = "0" Then sit = 6; at1$ = "4"; GoTo place EndIf If Val(at7$) + Val(at8$) + Val(at9$) = qaz Then If at7$ = "0" Then sit = 7; at7$ = "4"; GoTo place If at8$ = "0" Then sit = 8; at8$ = "4"; GoTo place If at9$ = "0" Then sit = 9; at9$ = "4"; GoTo place EndIf If Val(at7$) + Val(at5$) + Val(at3$) = qaz Then If at7$ = "0" Then sit = 7; at7$ = "4"; GoTo place If at5$ = "0" Then sit = 5; at5$ = "4"; GoTo place If at3$ = "0" Then sit = 3; at3$ = "4"; GoTo place EndIf If Val(at2$) + Val(at5$) + Val(at8$) = qaz Then If at2$ = "0" Then sit = 2; at2$ = "4"; GoTo place If at5$ = "0" Then sit = 5; at5$ = "4"; GoTo place If at8$ = "0" Then sit = 8; at8$ = "4"; GoTo place EndIf If Val(at3$) + Val(at6$) + Val(at9$) = qaz Then If at3$ = "0" Then sit = 3; at3$ = "4"; GoTo place If at6$ = "0" Then sit = 6; at6$ = "4"; GoTo place If at9$ = "0" Then sit = 9; at9$ = "4"; GoTo place EndIf Next zaq If at5$ = "0" Then sit = 5; at5$ = "4"; GoTo place If at1$ = "0" Then sit = 1; at1$ = "4"; GoTo place If at3$ = "0" Then sit = 3; at3$ = "4"; GoTo place If at9$ = "0" Then sit = 9; at9$ = "4"; GoTo place If at7$ = "0" Then sit = 7; at7$ = "4"; GoTo place If at4$ = "0" Then sit = 4; at4$ = "4"; GoTo place If at6$ = "0" Then sit = 6; at6$ = "4"; GoTo place If at2$ = "0" Then sit = 2; at2$ = "4"; GoTo place If at8$ = "0" Then sit = 8; at8$ = "4"; GoTo place
Placing the piece: Taking a piece Keeping track of number taken Placing piece in chosen spot place: Jump Palet1 (increm)+z20 Go Palet1 (increm) Wait 0.75 On 0 Wait 0.75 Jump Palet2 (sit)+z20 Go Palet2 (sit) Wait 0.75 Off 0 Wait 0.75 Jump P0 increm = increm + 1 GoSub isitover GoTo turn
Game Over: Declaring a winner youwin: answer = 0 hwin = hwin + 1 MsgBox you$, 0, title$, answer If answer = 1 Then Goto reset iwin: answer = 0 cwin = cwin + 1 MsgBox me$, 0, title$, answer If answer = 1 Then Goto reset draw: answer = 0 nowin = nowin + 1 MsgBox tie$, 0, title$, answer If answer = 1 Then Goto reset
Resetting: Putting back the pieces reset: If at1$ = "4" Then sit = 1; at1$ = "4"; Gosub replacec If at2$ = "4" Then sit = 2; at2$ = "4"; Gosub replacec If at3$ = "4" Then sit = 3; at3$ = "4"; Gosub replacec If at4$ = "4" Then sit = 4; at4$ = "4"; Gosub replacec If at5$ = "4" Then sit = 5; at5$ = "4"; Gosub replacec If at6$ = "4" Then sit = 6; at6$ = "4"; Gosub replacec If at7$ = "4" Then sit = 7; at7$ = "4"; Gosub replacec If at8$ = "4" Then sit = 8; at8$ = "4"; Gosub replacec If at9$ = "4" Then sit = 9; at9$ = "4"; Gosub replacec replacec: increm = increm - 1 Jump Palet2 (sit)+z20 Go Palet2 (sit) Wait 0.75 On 0 Wait 0.75 Jump Palet1 (increm)+z20 Go Palet1 (increm) Wait 0.75 Off 0 Wait 0.75 Jump P0 Return
Sensors: Reed switches respond to the magnets
Demo: I play the robot to a draw
Shall we play a game? Love to. How about Global Thermonuclear War. Wouldn't you prefer a nice game of chess? Later. Right now lets play Global Thermonuclear War. Fine.