наконец-то я зарегистрировался.
Теперь я готов поделится с вами своими идеями - для начала робот играющий в крестики-нолики.
Алгоритм программы заключается в том, чтобы в первую очередь не дать выиграть человеку, и лишь потом пытаться выиграть самому. Игровое поле выводится на экран, с указанием чей ход и кто выиграл.
A вот нескомпилированный код:
- Код: Выделить всё • Развернуть
int b;
int turn;
int win;
int which_turn; // 2 = bot
int finish;
int redraw;
int player_marker;
int n1; //n1 n2 n3
int n2; //n4 n5 n6
int n3; //n7 n8 n9
int n4; // game fields
int n5; // 1 - owned by player, 2 - owned by bot
int n6;
int n7;
int n8;
int n9;
// you'll need 1.sound files "! Backup.rso","round_draw.rso","Laughing 02.rso","Game Over.rso"
// 2.pictures "field.ric" ,"rturn1","rturn2","rturn3","rturn4"
sub drop_1()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,160);
b += 160;
RotateMotor(OUT_A, 10, -35);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, 35);
RotateMotor(OUT_B,40,-b);
}
sub drop_2()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,140);
b += 140;
RotateMotor(OUT_A, 10, -90);
Wait(10);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, 90);
RotateMotor(OUT_B,40,-b);
}
sub drop_3()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,160);
b += 160;
RotateMotor(OUT_A, 10, -125);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, 125);
RotateMotor(OUT_B,40,-b);
}
sub drop_4()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,140);
b += 140;
Wait(10);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_B,40,-b);
}
sub drop_5()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_B,40,-b);
}
sub drop_6()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,140);
b += 140;
RotateMotor(OUT_A, 10, 180);
Wait(10);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, 180);
RotateMotor(OUT_B,40,-b);
}
sub drop_7()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,160);
b += 160;
RotateMotor(OUT_A, 10, 55);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, -55);
RotateMotor(OUT_B,40,-b);
}
sub drop_8()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,140);
b += 140;
RotateMotor(OUT_A, 10, 90);
Wait(10);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, -90);
RotateMotor(OUT_B,40,-b);
}
sub drop_9()
{
SetSensor(IN_4, SENSOR_TOUCH);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,160);
b += 160;
RotateMotor(OUT_A, 10, 145);
RotateMotor(OUT_C, 40, 360);
RotateMotor(OUT_A, 10, -145);
RotateMotor(OUT_B,40,-b);
}
sub bot_turn()
{
turn = 0;
/*trying to win*/
if(n1 == 2 && n2 == 2 && n3 == 0 && turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
if(n1 == 2 && n2 == 0 && n3 == 2 && turn == 0)
{
drop_2();
n2 = 2;
turn = 1;
}
if(n1 == 0 && n2 == 2 && n3 == 2 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n4 == 2 && n5 == 2 && n6 == 0 && turn == 0)
{
drop_6();
n6 = 2;
turn = 1;
}
if(n4 == 2 && n5 == 0 && n6 == 2 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n4 == 0 && n5 == 2 && n6 == 2 && turn == 0)
{
drop_4();
n4 = 2;
turn = 1;
}
if(n7 == 2 && n8 == 2 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n7 == 2 && n8 == 0 && n9 == 2 && turn == 0)
{
drop_8();
n8 = 2;
turn = 1;
}
if(n7 == 0 && n8 == 2 && n9 == 2 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n1 == 2 && n4 == 2 && n7 == 0 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n1 == 2 && n4 == 0 && n7 == 2 && turn == 0)
{
drop_4();
n4 = 2;
turn = 1;
}
if(n1 == 0 && n4 == 2 && n7 == 2 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n2 == 2 && n5 == 2 && n8 == 0 && turn == 0)
{
drop_8();
n8 = 2;
turn = 1;
}
if(n2 == 2 && n5 == 0 && n8 == 2 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n2 == 0 && n5 == 2 && n8 == 2 && turn == 0)
{
drop_2();
n2 = 2;
turn = 1;
}
if(n3 == 2 && n6 == 2 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n3 == 2 && n6 == 0 && n9 == 2 && turn == 0)
{
drop_6();
n6 = 2;
turn = 1;
}
if(n3 == 0 && n6 == 2 && n9 == 2 && turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
if(n1 == 2 && n5 == 2 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n1 == 2 && n5 == 0 && n9 == 2 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n1 == 0 && n5 == 2 && n9 == 2 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n3 == 2 && n5 == 2 && n7 == 0&& turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n3 == 2 && n5 == 0 && n7 == 2&& turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n3 == 0 && n5 == 2 && n7 == 2&& turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
/* preventing player from winning*/
if(n1 == 1 && n2 == 1 && n3 == 0 && turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
if(n1 == 1 && n2 == 0 && n3 == 1 && turn == 0)
{
drop_2();
n2 = 2;
turn = 1;
}
if(n1 == 0 && n2 == 1 && n3 == 1 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n4 == 1 && n5 == 1 && n6 == 0 && turn == 0)
{
drop_6();
n6 = 2;
turn = 1;
}
if(n4 == 1 && n5 == 0 && n6 == 1 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n4 == 0 && n5 == 1 && n6 == 1 && turn == 0)
{
drop_4();
n4 = 2;
turn = 1;
}
if(n7 == 1 && n8 == 1 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n7 == 1 && n8 == 0 && n9 == 1 && turn == 0)
{
drop_8();
n8 = 2;
turn = 1;
}
if(n7 == 0 && n8 == 1 && n9 == 1 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n1 == 1 && n4 == 1 && n7 == 0 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n1 == 1 && n4 == 0 && n7 == 1 && turn == 0)
{
drop_4();
n4 = 2;
turn = 1;
}
if(n1 == 0 && n4 == 1 && n7 == 1 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n2 == 1 && n5 == 1 && n8 == 0 && turn == 0)
{
drop_8();
n8 = 2;
turn = 1;
}
if(n2 == 1 && n5 == 0 && n8 == 1 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n2 == 0 && n5 == 1 && n8 == 1 && turn == 0)
{
drop_2();
n2 = 2;
turn = 1;
}
if(n3 == 1 && n6 == 1 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n3 == 1 && n6 == 0 && n9 == 1 && turn == 0)
{
drop_6();
n6 = 2;
turn = 1;
}
if(n3 == 0 && n6 == 1 && n9 == 1 && turn == 0)
{
drop_9();
n3 = 2;
turn = 1;
}
if(n1 == 1 && n5 == 1 && n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n1 == 1 && n5 == 0 && n9 == 1 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n1 == 0 && n5 == 1 && n9 == 1 && turn == 0)
{
drop_9();
n1 = 2;
turn = 1;
}
if(n3 == 1 && n5 == 1 && n7 == 0 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n3 == 1 && n5 == 0 && n7 == 1 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n3 == 0 && n5 == 1 && n7 == 1 && turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
/* if there aren't any of listed combinations*/
if(n5 == 0 && turn == 0)
{
drop_5();
n5 = 2;
turn = 1;
}
if(n1 == 0 && turn == 0)
{
drop_1();
n1 = 2;
turn = 1;
}
if(n3 == 0 && turn == 0)
{
drop_3();
n3 = 2;
turn = 1;
}
if(n7 == 0 && turn == 0)
{
drop_7();
n7 = 2;
turn = 1;
}
if(n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
if(n2 == 0 && turn == 0)
{
drop_2();
n2 = 2;
turn = 1;
}
if(n4 == 0 && turn == 0)
{
drop_4();
n4 = 2;
turn = 1;
}
if(n6 == 0 && turn == 0)
{
drop_6();
n6 = 2;
turn = 1;
}
if(n9 == 0 && turn == 0)
{
drop_9();
n9 = 2;
turn = 1;
}
turn = 0;
}
sub scan()
{
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,200);
b += 200;
if(SENSOR_3 >= player_marker)
{
n5 = 1;
redraw = 1;
} //5
RotateMotor(OUT_B,40,130);
b += 130;
if(SENSOR_3 >= player_marker)
{
n4 = 1;
redraw = 1;
} //4
RotateMotor(OUT_A, 10, -35);
RotateMotor(OUT_B,20,40);
b += 40;
if(SENSOR_3 >= player_marker)
{
n1 = 1;
redraw = 1;
} //1
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,-40);
b -= 40;
if(SENSOR_3 >= player_marker)
{
n2 = 1;
redraw = 1;
} //2
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,40);
b += 40;
if(SENSOR_3 >= player_marker)
{
n3 = 1;
redraw = 1;
} //3
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,-40);
b -= 40;
if(SENSOR_3 >= player_marker)
{
n6 = 1;
redraw = 1;
} //6
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,40);
b += 40;
if(SENSOR_3 >= player_marker)
{
n9 = 1;
redraw = 1;
} //9
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,-40);
b -= 40;
if(SENSOR_3 >= player_marker)
{
n8 = 1;
redraw = 1;
} //8
RotateMotor(OUT_A, 10, -45);
RotateMotor(OUT_B,20,40);
b += 40;
if(SENSOR_3 >= player_marker)
{
n7 = 1;
redraw = 1;
} //7
RotateMotor(OUT_A, 10, -55);// reset marker
RotateMotor(OUT_B,40,-b); //done
}
sub win_check()
{
if(n1 == 2 && n2 == 2 && n3 == 2) //bot
{
win = 2;
}
if(n4 == 2 && n5 == 2 && n6 == 2)
{
win = 2;
}
if(n7 == 2 && n8 == 2 && n9 == 2)
{
win = 2;
}
if(n1 == 2 && n4 == 2 && n7 == 2)
{
win = 2;
}
if(n2 == 2 && n5 == 2 && n8 == 2)
{
win = 2;
}
if(n3 == 2 && n6 == 2 && n9 == 2)
{
win = 2;
}
if(n1 == 2 && n5 == 2 && n9 == 2)
{
win = 2;
}
if(n3 == 2 && n5 == 2 && n7 == 2)
{
win = 2;
}
if(n1 == 1 && n2 == 1 && n3 == 1) //player
{
win = 1;
}
if(n4 == 1 && n5 == 1 && n6 == 1)
{
win = 1;
}
if(n7 == 1 && n8 == 1 && n9 == 1)
{
win = 1;
}
if(n1 == 1 && n4 == 1 && n7 == 1)
{
win = 1;
}
if(n2 == 1 && n5 == 1 && n8 == 1)
{
win = 1;
}
if(n3 == 1 && n6 == 1 && n9 == 1)
{
win = 1;
}
if(n1 == 1 && n5 == 1 && n9 == 1)
{
win = 1;
}
if(n3 == 1 && n5 == 1 && n7 == 1)
{
win = 1;
}
}
sub win_animation()
{
if(n1 == 2 && n2 == 2 && n3 == 2) //bot
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,49,29,44); // x right-center 2
LineOut(24,44,29,49);
LineOut(24,59,29,54); // x right-up 1
LineOut(24,54,29,59);
LineOut(24,39,29,34); // x right-down 3
LineOut(24,34,29,39);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n4 == 2 && n5 == 2 && n6 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(14,49,19,44); // x center 5
LineOut(14,44,19,49);
LineOut(14,59,19,54); // x center-up 4
LineOut(14,54,19,59);
LineOut(14,39,19,34); // x center-down 6
LineOut(14,34,19,39);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n7 == 2 && n8 == 2 && n9 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(4,49,9,44); // x left-center 8
LineOut(4,44,9,49);
LineOut(4,59,9,54); // x left-up 7
LineOut(4,54,9,59);
LineOut(4,39,9,34); // x left-down 9
LineOut(4,34,9,39);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n1 == 2 && n4 == 2 && n7 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,59,29,54); // x right-up 1
LineOut(24,54,29,59);
LineOut(14,59,19,54); // x center-up 4
LineOut(14,54,19,59);
LineOut(4,59,9,54); // x left-up 7
LineOut(4,54,9,59);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n2 == 2 && n5 == 2 && n8 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,49,29,44); // x right-center 2
LineOut(24,44,29,49);
LineOut(14,49,19,44); // x center 5
LineOut(14,44,19,49);
LineOut(4,49,9,44); // x left-center 8
LineOut(4,44,9,49);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n3 == 2 && n6 == 2 && n9 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,39,29,34); // x right-down 3
LineOut(24,34,29,39);
LineOut(14,39,19,34); // x center-down 6
LineOut(14,34,19,39);
LineOut(4,39,9,34); // x left-down 9
LineOut(4,34,9,39);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n1 == 2 && n5 == 2 && n9 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,59,29,54); // x right-up 1
LineOut(24,54,29,59);
LineOut(14,49,19,44); // x center 5
LineOut(14,44,19,49);
LineOut(4,39,9,34); // x left-down 9
LineOut(4,34,9,39);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n3 == 2 && n5 == 2 && n7 == 2)
{
win = 2;
while(ButtonState(BTNCENTER) == 0)
{
TextOut(2,7,"Robot wins!");
LineOut(24,39,29,34); // x right-down 3
LineOut(24,34,29,39);
LineOut(14,49,19,44); // x center 5
LineOut(14,44,19,49);
LineOut(4,59,9,54); // x left-up 7
LineOut(4,54,9,59);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n1 == 1 && n2 == 1 && n3 == 1) //player
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,44,5,5); // brick right-center 2
RectOut(25,45,4,4);
RectOut(26,46,3,3);
RectOut(27,47,2,2);
PointOut(28,48);
RectOut(24,54,5,5); // brick right-up 1
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
RectOut(24,34,5,5); // brick right-down 3
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n4 == 1 && n5 == 1 && n6 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(14,44,5,5); // brick center 5
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
RectOut(14,54,5,5); // brick center-up 4
RectOut(15,55,4,4);
RectOut(16,56,3,3);
RectOut(17,57,2,2);
PointOut(18,58);
RectOut(14,34,5,5); // brick center-down 6
RectOut(15,35,4,4);
RectOut(16,36,3,3);
RectOut(17,37,2,2);
PointOut(18,38);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n7 == 1 && n8 == 1 && n9 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(4,44,5,5); // brick left-center 8
RectOut(5,45,4,4);
RectOut(6,46,3,3);
RectOut(7,47,2,2);
PointOut(8,48);
RectOut(4,54,5,5); // brick left-up 7
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
RectOut(4,34,5,5); // brick left-down 9
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n1 == 1 && n4 == 1 && n7 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,54,5,5); // brick right-up 1
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
RectOut(14,54,5,5); // brick center-up 4
RectOut(15,55,4,4);
RectOut(16,56,3,3);
RectOut(17,57,2,2);
PointOut(18,58);
RectOut(4,54,5,5); // brick left-up 7
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n2 == 1 && n5 == 1 && n8 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,44,5,5); // brick right-center 2
RectOut(25,45,4,4);
RectOut(26,46,3,3);
RectOut(27,47,2,2);
PointOut(28,48);
RectOut(14,44,5,5); // brick center 5
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
RectOut(4,44,5,5); // brick left-center 8
RectOut(5,45,4,4);
RectOut(6,46,3,3);
RectOut(7,47,2,2);
PointOut(8,48);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n3 == 1 && n6 == 1 && n9 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,34,5,5); // brick right-down 3
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
RectOut(14,34,5,5); // brick center-down 6
RectOut(15,35,4,4);
RectOut(16,36,3,3);
RectOut(17,37,2,2);
PointOut(18,38);
RectOut(4,34,5,5); // brick left-down 9
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n1 == 1 && n5 == 1 && n9 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,54,5,5); // brick right-up 1
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
RectOut(14,44,5,5); // brick center 5
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
RectOut(4,34,5,5); // brick left-down 9
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
if(n3 == 1 && n5 == 1 && n7 == 1)
{
win = 1;
TextOut(2,7,"Player wins!");
while(ButtonState(BTNCENTER) == 0)
{
RectOut(24,34,5,5); // brick right-down 3
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
RectOut(14,44,5,5); // brick center 5
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
RectOut(4,54,5,5); // brick left-up 7
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
Wait(500);
ClearScreen();
GraphicOut(-67,31,"field.ric");
Wait(500);
}
}
}
/*tasks*/
task display_scores()
{
GraphicOut(-67,31,"field.ric");;
while(win == 0)
{
redraw = 0;
GraphicOut(-67,31,"field.ric");
if(n1 == 1)
{
RectOut(24,54,5,5); // brick right-up
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
}
if(n1 == 2)
{
LineOut(24,59,29,54); // x right-up
LineOut(24,54,29,59);
}
if(n2 == 1)
{
RectOut(24,44,5,5); // brick right-center
RectOut(25,45,4,4);
RectOut(26,46,3,3);
RectOut(27,47,2,2);
PointOut(28,48);
}
if(n2 == 2)
{
LineOut(24,49,29,44); // x right-center
LineOut(24,44,29,49);
}
if(n3 == 1)
{
RectOut(24,34,5,5); // brick right-down
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
}
if(n3 == 2)
{
LineOut(24,39,29,34); // x right-down
LineOut(24,34,29,39);
}
if(n4 == 1)
{
RectOut(14,54,5,5); // brick center-up
RectOut(15,55,4,4);
RectOut(16,56,3,3);
RectOut(17,57,2,2);
PointOut(18,58);
}
if(n4 == 2)
{
LineOut(14,59,19,54); // x center-up
LineOut(14,54,19,59);
}
if(n5 == 1)
{
RectOut(14,44,5,5); // brick center
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
}
if(n5 == 2)
{
LineOut(14,49,19,44); // x center
LineOut(14,44,19,49);
}
if(n6 == 1)
{
RectOut(14,34,5,5); // brick center-down
RectOut(15,35,4,4);
RectOut(16,36,3,3);
RectOut(17,37,2,2);
PointOut(18,38);
}
if(n6 == 2)
{
LineOut(14,39,19,34); // x center-down
LineOut(14,34,19,39);
}
if(n7 == 1)
{
RectOut(4,54,5,5); // brick left-up
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
}
if(n7 == 2)
{
LineOut(4,59,9,54); // x left-up
LineOut(4,54,9,59);
}
if(n8 == 1)
{
RectOut(4,44,5,5); // brick left-center
RectOut(5,45,4,4);
RectOut(6,46,3,3);
RectOut(7,47,2,2);
PointOut(8,48);
}
if(n8 == 2)
{
LineOut(4,49,9,44); // x left-center
LineOut(4,44,9,49);
}
if(n9 == 1)
{
RectOut(4,34,5,5); // brick left-down
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
}
if(n9 == 2)
{
LineOut(4,39,9,34); // x left-down
LineOut(4,34,9,39);
}
while(redraw == 0)
}
GraphicOut(-67,31,"field.ric");
if(n1 == 1)
{
RectOut(24,54,5,5); // brick right-up
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
}
if(n1 == 2)
{
LineOut(24,59,29,54); // x right-up
LineOut(24,54,29,59);
}
if(n2 == 1)
{
RectOut(24,44,5,5); // brick right-center
RectOut(25,45,4,4);
RectOut(26,46,3,3);
RectOut(27,47,2,2);
PointOut(28,48);
}
if(n2 == 2)
{
LineOut(24,49,29,44); // x right-center
LineOut(24,44,29,49);
}
if(n3 == 1)
{
RectOut(24,34,5,5); // brick right-down
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
}
if(n3 == 2)
{
LineOut(24,39,29,34); // x right-down
LineOut(24,34,29,39);
}
if(n4 == 1)
{
RectOut(14,54,5,5); // brick center-up
RectOut(15,55,4,4);
RectOut(16,56,3,3);
RectOut(17,57,2,2);
PointOut(18,58);
}
if(n4 == 2)
{
LineOut(14,59,19,54); // x center-up
LineOut(14,54,19,59);
}
if(n5 == 1)
{
RectOut(14,44,5,5); // brick center
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
}
if(n5 == 2)
{
LineOut(14,49,19,44); // x center
LineOut(14,44,19,49);
}
if(n6 == 1)
{
RectOut(14,34,5,5); // brick center-down
RectOut(15,35,4,4);
RectOut(16,36,3,3);
RectOut(17,37,2,2);
PointOut(18,38);
}
if(n6 == 2)
{
LineOut(14,39,19,34); // x center-down
LineOut(14,34,19,39);
}
if(n7 == 1)
{
RectOut(4,54,5,5); // brick left-up
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
}
if(n7 == 2)
{
LineOut(4,59,9,54); // x left-up
LineOut(4,54,9,59);
}
if(n8 == 1)
{
RectOut(4,44,5,5); // brick left-center
RectOut(5,45,4,4);
RectOut(6,46,3,3);
RectOut(7,47,2,2);
PointOut(8,48);
}
if(n8 == 2)
{
LineOut(4,49,9,44); // x left-center
LineOut(4,44,9,49);
}
if(n9 == 1)
{
RectOut(4,34,5,5); // brick left-down
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
}
if(n9 == 2)
{
LineOut(4,39,9,34); // x left-down
LineOut(4,34,9,39);
}
}
task display_turn()
{
while(win == 0 && finish == 0)
{
while(which_turn == 1)
{
TextOut(2,7,"Your turn");
while(which_turn == 1);
ClearScreen();
redraw = 1;
}
while(which_turn == 2 && finish == 0)
{
TextOut(2,7,"Robots turn");
TextOut(60,LCD_LINE5,"Please");
TextOut(65,LCD_LINE6,"wait");
while(which_turn == 2)
{
GraphicOut(70,40,"rturn1.ric");
Wait(700);
GraphicOut(70,40,"rturn2.ric");
Wait(700);
GraphicOut(70,40,"rturn3.ric");
Wait(700);
GraphicOut(70,40,"rturn4.ric");
Wait(700);
}
ClearScreen();
redraw = 1;
}
}
}
task game()
{
Wait(1000);
/* 1st turn */
if(win == 0)
{
which_turn = 1;
while(ButtonState(BTNCENTER) == 0);
which_turn = 2;
scan();
redraw = 1;
win_check();
if(win == 0)
{
bot_turn();
redraw = 1;
}
win_check();
}
/* 2nd turn */
if(win == 0)
{
which_turn = 1;
while(ButtonState(BTNCENTER) == 0);
which_turn = 2;
scan();
redraw = 1;
win_check();
if(win == 0)
{
bot_turn();
redraw = 1;
}
win_check();
}
/* 3rd turn */
if(win == 0)
{
which_turn = 1;
while(ButtonState(BTNCENTER) == 0);
which_turn = 2;
scan();
redraw = 1;
win_check();
if(win == 0)
{
bot_turn();
redraw = 1;
}
win_check();
}
/* 4th turn */
if(win == 0)
{
which_turn = 1;
while(ButtonState(BTNCENTER) == 0);
which_turn = 2;
scan();
redraw = 1;
win_check();
if(win == 0)
{
bot_turn();
redraw = 1;
}
win_check();
}
/* 5ft turn */
if(win == 0)
{
which_turn = 1;
while(ButtonState(BTNCENTER) == 0);
which_turn = 2;
scan();
redraw = 1;
win_check();
finish = 1;
ClearScreen();
}
if(win == 0)
{
StopTask(display_turn);
ClearScreen();
redraw = 1;
TextOut(2,7,"Draw");
PlayFile("round_draw.rso");
while(ButtonState(BTNCENTER) == 0);
}
if(win == 1)
{
StopTask(display_turn);
ClearScreen();
redraw = 1;
win_animation();
}
if(win == 2)
{
StopTask(display_turn);
ClearScreen();
redraw = 1;
win_animation();
PlayFile("Laughing 02.rso");
}
PlayFile("Game Over.rso");
finish = 1;
while(ButtonState(BTNCENTER) == 0);
Wait(1000);
StopAllTasks();
}
task please_wait()
{
while(which_turn == 2);
TextOut(60,LCD_LINE5,"Please");
TextOut(65,LCD_LINE6,"wait");
while(which_turn == 2)
{
GraphicOut(70,40,"rturn1.ric");
Wait(700);
GraphicOut(70,40,"rturn2.ric");
Wait(700);
GraphicOut(70,40,"rturn3.ric");
Wait(700);
GraphicOut(70,40,"rturn4.ric");
Wait(700);
}
ClearScreen();
redraw = 1;
}
task main()
{
SetSensorType(IN_3, IN_TYPE_LIGHT_ACTIVE);
SetSensorMode(IN_3, IN_MODE_PCTFULLSCALE);
SetSensor(IN_4, SENSOR_TOUCH); // sensors
ClearScreen();
repeat(5)
{
TextOut(2,LCD_LINE1,"_");
Wait(300);
ClearScreen();
Wait(300);
}
TextOut(2,LCD_LINE1, "Loading software...");
TextOut(2,LCD_LINE2,".");
Wait(200);
TextOut(2,LCD_LINE2,"..");
Wait(200);
TextOut(2,LCD_LINE2,"...");
Wait(200);
TextOut(2,LCD_LINE2,"...");
Wait(200);
TextOut(2,LCD_LINE2,"....");
Wait(200);
TextOut(2,LCD_LINE2,".....");
Wait(200);
TextOut(2,LCD_LINE2,"......");
Wait(200);
TextOut(2,LCD_LINE2,".......");
Wait(200);
TextOut(2,LCD_LINE2,"........");
Wait(200);
TextOut(2,LCD_LINE2,".........");
Wait(200);
TextOut(2,LCD_LINE2,"..........");
Wait(200);
TextOut(2,LCD_LINE2,"...........");
Wait(200);
TextOut(2,LCD_LINE2,"............");
Wait(200);
TextOut(2,LCD_LINE2,".............");
Wait(200);
TextOut(2,LCD_LINE2,"..............");
Wait(200);
TextOut(2,LCD_LINE2,"...............");
Wait(200);
TextOut(2,LCD_LINE2,"................");
TextOut(40,LCD_LINE4, "Done");
PlayFile("! Backup.rso");
Wait(1500);
ClearScreen();
repeat(5)
{
TextOut(2,LCD_LINE1,"_");
Wait(300);
ClearScreen();
Wait(300);
}
TextOut(2,LCD_LINE1,"Checking files");
TextOut(2,LCD_LINE2, "on C:/");
Wait(2000);
ClearScreen();
TextOut(2,LCD_LINE2, "Calibration:");
TextOut(2,LCD_LINE3, "place a marker");
TextOut(2,LCD_LINE4, "in the middle");
TextOut(2,LCD_LINE5, "and press OK");
while(ButtonState(BTNCENTER) == 0);
OnRev(OUT_B, 40);
while(SENSOR_4 == 0);
Off(OUT_B);
b = MotorRotationCount(OUT_B);
RotateMotor(OUT_B,40,200);
b += 200;
player_marker = SENSOR_3;
player_marker -= 7;
RotateMotor(OUT_B,40,-b);
ClearScreen();
TextOut(2,LCD_LINE2, "Remove marker.");
while(ButtonState(BTNCENTER) == 0);
ClearScreen();
TextOut(2,LCD_LINE1,"Load aka13's ");
TextOut(2,LCD_LINE2,"Tic Tac Toe ");
TextOut(2,LCD_LINE3,"player? ");
TextOut(35,LCD_LINE8, "ENTER");
while(ButtonState(BTNCENTER) == 0);
repeat(4)
{
ClearScreen();
TextOut(35,LCD_LINE7,"Loading");
GraphicOut(-67,31,"field.ric");
RectOut(24,34,5,5); // brick right-down
RectOut(25,35,4,4);
RectOut(26,36,3,3);
RectOut(27,37,2,2);
PointOut(28,38);
Wait(200);
RectOut(14,34,5,5); // brick center-down
RectOut(15,35,4,4);
RectOut(16,36,3,3);
RectOut(17,37,2,2);
PointOut(18,38);
Wait(200);
RectOut(4,34,5,5); // brick left-down
RectOut(5,35,4,4);
RectOut(6,36,3,3);
RectOut(7,37,2,2);
PointOut(8,38);
Wait(200);
RectOut(4,44,5,5); // brick left-center
RectOut(5,45,4,4);
RectOut(6,46,3,3);
RectOut(7,47,2,2);
PointOut(8,48);
Wait(200);
RectOut(4,54,5,5); // brick left-up
RectOut(5,55,4,4);
RectOut(6,56,3,3);
RectOut(7,57,2,2);
PointOut(8,58);
Wait(200);
RectOut(14,54,5,5); // brick center-up
RectOut(15,55,4,4);
RectOut(16,56,3,3);
RectOut(17,57,2,2);
PointOut(18,58);
Wait(200);
RectOut(24,54,5,5); // brick right-up
RectOut(25,55,4,4);
RectOut(26,56,3,3);
RectOut(27,57,2,2);
PointOut(28,58);
Wait(200);
RectOut(24,44,5,5); // brick right-center
RectOut(25,45,4,4);
RectOut(26,46,3,3);
RectOut(27,47,2,2);
PointOut(28,48);
Wait(200);
RectOut(14,44,5,5); // brick center
RectOut(15,45,4,4);
RectOut(16,46,3,3);
RectOut(17,47,2,2);
PointOut(18,48);
Wait(200);
}
ClearScreen();
while(ButtonState(BTNCENTER) == 0)
{
TextOut(20,LCD_LINE2,"Press Enter");
TextOut(20,LCD_LINE3,"to start");
Wait(300);
ClearScreen();
Wait(300);
}
while(ButtonState(BTNCENTER) == 0)
Precedes(game,display_scores,display_turn,please_wait);
}
Инструкции для постройки есть, если кому интересно, могу дать.
P.S. И если несложно, поставьте на ютубе оценку)