- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
if(is_ai_on && !white_move)
			{
				int tries;
			start:
					srand (time(NULL));
				select_figure:
					int figure = rand() % (game_field.figures.size() - 1) + 0;
					if(game_field.figures[figure]->IsWhiteFigure()) goto select_figure;
					int pos_x;
					int pos_y;
					tries = 0;
				try_move:
				try
				{
					switch(game_field.figures[figure]->GetType())
					{
						case PawnType:
						{
							pos_x = rand() % (game_field.figures[figure]->GetPositionX() + 2) + (game_field.figures[figure]->GetPositionX() - 2);
							if(pos_x < 0) pos_x = 0;
							if(pos_x >= game_field.size) pos_x = game_field.size - 1;
							pos_y = game_field.figures[figure]->GetPositionY() + 1;
							if(pos_x == game_field.figures[figure]->GetPositionX() &&
							   pos_y == game_field.figures[figure]->GetPositionY())
							   {
									if(tries < 6)
									{
										tries++;
										goto try_move;
									}
									else
									{
										goto select_figure;
									}
							   }
						}break;
						default:
						{
							pos_x = rand() % (game_field.figures[figure]->GetPositionX() + 5) + (game_field.figures[figure]->GetPositionX() - 5);
							pos_y = rand() % (game_field.figures[figure]->GetPositionY() + 5) + (game_field.figures[figure]->GetPositionY() - 5);
							if(pos_x < 0) pos_x = 0;
							if(pos_x >= game_field.size) pos_x = game_field.size - 1;
							if(pos_y < 0) pos_y = 0;
							if(pos_y >= game_field.size) pos_y= game_field.size - 1;
							if(pos_x == game_field.figures[figure]->GetPositionX() &&
							   pos_y == game_field.figures[figure]->GetPositionY())
							   {
									if(tries < 6)
									{
										tries++;
										goto try_move;
									}
									else
									{
										goto select_figure;
									}
							   }
						}break;
					}
					game_field.DoMove(figure, pos_x, pos_y, this->white_move);
				}
				catch(...)
				{
					if(tries < 6)
					{
						tries++;
						goto try_move;
					}
					else
					{
						goto select_figure;
					}
				}
				this->white_move = true;
			}
                                 
        
Комментарии (8) RSS
Добавить комментарий