-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunicator.cpp
More file actions
75 lines (54 loc) · 2.01 KB
/
Communicator.cpp
File metadata and controls
75 lines (54 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
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
//
// Communicator.cpp
// BCAI
//
// Created by Max Botviniev on 15.10.15.
// Copyright (c) 2015 Max Botviniev. All rights reserved.
//
#include "Communicator.h"
//Debug
#include <iostream>
namespace BCAI {
//Init Point for AI block
char * Communicator::GetDecision( const char * game_p ) const {
//...
char * AI_move = new char[4] /*{ 'A', '7', 'A', '6' }*/ ;
//Get Move
//Board board( input_info_p );
//Piece * result = board.GetMove();
//....
InputFill(AI_move);
return AI_move;
}
bool Communicator::RulesAdvisor( const char * game_p, const char * move_p, bool white_turn_v ) const {
//Empty input case
//-------------------
if( strlen(move_p) == 0 || strlen(game_p) == 0 ) {
std::cout << "Waste RulesAdvisor call." << std::endl;
return false;
}
//-------------------
//If User moves other side piece
//-------------------
char color_l = '0';
//Foreach str-Piece: +RA1
for( int str_piece_index_l = 0; str_piece_index_l < strlen(game_p); str_piece_index_l += 4 ) {
for( int i = 2; i < 4; i++) {
int index = str_piece_index_l + i;
if( game_p[ index ] != move_p[ i -2 ] ) break;
else if( i == 3 ) {
color_l = game_p[ str_piece_index_l ];
}
}
}
if( color_l != '+' && color_l != '-' ) std::cout << "Something wrong: " << color_l << std::endl;
bool white_piece_l = color_l == '+';
if( white_piece_l != white_turn_v ) {
std::cout << "Not alowed to move piece of oponnent: " << move_p << std::endl;
return false;
}
//-------------------
Board board(game_p);
return board.AllowedMove(move_p);
}
}