Having worked as a farmer and woodcutter for most of my life i became determined to do something that would leave my mark after i was gone. Since then i got back to studies, and i have now a master degree in Electrotecnical Engineering as well as a degree on Electromechanical Engineering. On my free time i like playing and so i became interested in creating my own games or, in the shorter term, modding games to get something closer to what i would like games to be.

Report RSS Programming manipulator robots

Posted by on

So this semester at the university one of the tasks was programming a manipulator robot called Scorbot to play tic tac toe. This small extract is related with one of the defensive tactics i set up for the robot so it never loses (it either draws or wins).

The playing grid is something like this:
A1 A2 A3
B1 B2 B3
C1 C2 C3

As you can see although the program is simple and the task is also simple, it gets pretty big, pretty fast. Just for corner strategies (or "estratégia canto") i have 3 more for defense alone and another one for the robot playing in the center. A simillar number of attack strategies exist so the program is something like 2000 lines of code right now. Still this kind of program works with most important features of an industrial manipulator, from pick and place to conditional placement and many more.

ESTCANTO1:
Set Variable O1 = 2
Call Subroutine Pos9
Call Subroutine Limpa
Call Subroutine Aguardar
IF A1==1 jump to Canto1
IF A2==1 jump to Canto2
IF A3==1 jump to Canto3
IF B1==1 jump to Canto4
IF B3==1 jump to Canto5
IF C1==1 jump to Canto6
IF C2==1 jump to Canto7
Canto1:
Call Subroutine Pos7
Call Subroutine Limpa
Call Subroutine Aguardar
IF C2==0 jump to Win2
IF C2==1 jump to Canto11
Canto11:
Call Subroutine Pos2
Call Subroutine Limpa
Call Subroutine Aguardar
IF B1==0 jump to End5
IF B3==0 jump to End4
Canto2:
Call Subroutine Pos8
Call Subroutine Limpa
Call Subroutine Aguardar
IF C1==0 jump to Win3
IF C1==1 jump to Canto21
Canto21:
Call Subroutine Pos1
Call Subroutine Limpa
Call Subroutine Aguardar
IF B1==0 jump to End5
IF B3==0 jump to End4
Canto3:
Call Subroutine Pos7
Call Subroutine Limpa
Call Subroutine Aguardar
IF C2==0 jump to Win2
IF C2==1 jump to Canto31
Canto31:
Call Subroutine Pos2
Call Subroutine Limpa
Call Subroutine Aguardar
IF B1==0 jump to End5
IF B3==0 jump to End4
Canto4:
Call Subroutine Pos6
Call Subroutine Limpa
Call Subroutine Aguardar
IF A3==0 jump to Win6
IF A3==1 jump to Canto41
Canto41:
Call Subroutine Pos7
Call Subroutine Limpa
Call Subroutine Aguardar
IF C2==0 jump to Win2
IF A2==0 jump to End7
Canto5:
Call Subroutine Pos4
Call Subroutine Limpa
Call Subroutine Aguardar
IF A2==1 jump to Canto51
IF A3==1 jump to Canto52
IF C1==1 jump to Canto53
IF C2==1 jump to Canto54
IF A1==1 jump to Canto54
Canto51:
Call Subroutine Pos8
Call Subroutine Limpa
Call Subroutine Aguardar
IF C1==0 jump to Win3
IF C1==1 jump to End6
Canto52:
Call Subroutine Pos7
Call Subroutine Limpa
Call Subroutine Aguardar
IF C2==0 jump to Win2
IF C2==1 jump to End7
Canto53:
Call Subroutine Pos3
Call Subroutine Limpa
Call Subroutine Aguardar
IF C2==0 jump to End2
IF A2==0 jump to End7
Canto54:
Call Subroutine Pos2
Call Subroutine Limpa
Call Subroutine Aguardar
IF A3==0 jump to End6
IF C1==0 jump to End3
Canto6:
Call Subroutine Pos3
Call Subroutine Limpa
Call Subroutine Aguardar
IF B3==0 jump to Win4
IF B3==1 jump to Canto61
Canto61:
Call Subroutine Pos4
Call Subroutine Limpa
Call Subroutine Aguardar
IF A2==0 jump to End7
IF C2==0 jump to End2
Canto7:
Call Subroutine Pos2
Call Subroutine Limpa
Call Subroutine Aguardar
IF A3==1 jump to Canto71
IF B1==1 jump to Canto72
IF B3==1 jump to Canto73
IF C1==1 jump to Canto74
IF A1==1 jump to Canto71
Canto71:
Call Subroutine Pos7
Call Subroutine Limpa
Call Subroutine Aguardar
IF B1==0 jump to End5
IF B3==0 jump to End4
Canto72:
Call Subroutine Pos6
Call Subroutine Limpa
Call Subroutine Aguardar
IF A3==0 jump to Win6
IF C1==0 jump to End3
Canto73:
Call Subroutine Pos4
Call Subroutine Limpa
Call Subroutine Aguardar
IF C1==0 jump to End3
IF A3==0 jump to End6
Canto74:
Call Subroutine Pos3
Call Subroutine Limpa
Call Subroutine Aguardar
IF B3==0 jump to Win4
IF B1==0 jump to End5

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: