Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (2)
...@@ -18,7 +18,7 @@ bool Compiler::nullCheck(SyntaxTree* ptr, std::string warning) ...@@ -18,7 +18,7 @@ bool Compiler::nullCheck(SyntaxTree* ptr, std::string warning)
return true; return true;
} }
// Extrctors // Extractors
SyntaxTree* Compiler::extract(SyntaxTree* ptr, int index, std::string warning) SyntaxTree* Compiler::extract(SyntaxTree* ptr, int index, std::string warning)
{ {
if (!nullCheck(ptr, warning)) if (!nullCheck(ptr, warning))
......
...@@ -30,7 +30,7 @@ void Game::nextMove() ...@@ -30,7 +30,7 @@ void Game::nextMove()
while (true) while (true)
{ {
std::string move_name = players->makeMove(state_data, moves_map); std::string move_name = players->makeMove(state_data, moves_map);
if (moves->makeMove(move_name)) // Break if valid mowe was executed if (moves->makeMove(move_name)) // Break if valid move was executed
break; break;
} }
......
...@@ -78,26 +78,26 @@ ...@@ -78,26 +78,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
......
...@@ -286,37 +286,37 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); ...@@ -286,37 +286,37 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
*yy_cp = '\0'; \ *yy_cp = '\0'; \
yy_c_buf_p = yy_cp; yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 23 #define YY_NUM_RULES 24
#define YY_END_OF_BUFFER 24 #define YY_END_OF_BUFFER 25
static yyconst short int yy_accept[85] = static yyconst short int yy_accept[89] =
{ 0, { 0,
0, 0, 24, 23, 22, 21, 21, 21, 16, 21, 0, 0, 25, 24, 23, 21, 21, 21, 21, 16,
21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 23, 11, 14, 16, 12, 10, 13, 20, 20, 20, 20, 24, 11, 14, 0, 16, 12,
20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 10, 13, 20, 20, 8, 20, 20, 20, 20, 20,
20, 20, 20, 15, 20, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 15, 0, 22, 20, 5,
20, 19, 20, 20, 20, 6, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 20, 20, 20, 6,
20, 20, 20, 20, 17, 20, 4, 20, 20, 2, 20, 20, 20, 20, 20, 20, 20, 20, 17, 20,
20, 9, 20, 20, 7, 20, 20, 1, 20, 20, 4, 20, 20, 2, 20, 9, 20, 20, 7, 20,
20, 3, 18, 0 20, 1, 20, 20, 20, 3, 18, 0
} ; } ;
static yyconst int yy_ec[256] = static yyconst int yy_ec[256] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 3, 1, 4, 4, 4, 5, 1, 4, 1, 2, 4, 1, 5, 5, 5, 6, 1, 5,
4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 5, 5, 5, 5, 5, 5, 7, 8, 8, 8,
6, 6, 6, 6, 6, 6, 6, 1, 4, 7, 8, 8, 8, 8, 8, 8, 8, 1, 5, 9,
8, 9, 1, 1, 10, 11, 12, 12, 13, 14, 10, 11, 1, 1, 12, 13, 14, 14, 15, 16,
12, 15, 16, 12, 12, 17, 18, 19, 20, 21, 14, 17, 18, 14, 14, 19, 20, 21, 22, 23,
12, 22, 23, 24, 25, 26, 27, 12, 28, 12, 14, 24, 25, 26, 27, 28, 29, 14, 30, 14,
4, 1, 4, 1, 29, 1, 30, 12, 12, 12, 5, 1, 5, 1, 31, 1, 32, 14, 14, 14,
31, 32, 12, 12, 12, 12, 12, 33, 12, 12, 33, 34, 14, 14, 14, 14, 14, 35, 14, 14,
12, 12, 12, 34, 35, 36, 37, 12, 12, 12, 14, 14, 14, 36, 37, 38, 39, 14, 14, 14,
12, 12, 4, 38, 4, 1, 1, 1, 1, 1, 14, 14, 5, 40, 5, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
...@@ -333,76 +333,78 @@ static yyconst int yy_ec[256] = ...@@ -333,76 +333,78 @@ static yyconst int yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst int yy_meta[39] = static yyconst int yy_meta[41] =
{ 0, { 0,
1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
2, 2, 2, 2, 2, 2, 2, 1
} ; } ;
static yyconst short int yy_base[86] = static yyconst short int yy_base[91] =
{ 0, { 0,
0, 0, 100, 101, 101, 91, 101, 93, 91, 88, 0, 0, 107, 108, 108, 96, 108, 99, 97, 95,
87, 86, 0, 73, 25, 30, 75, 78, 66, 71, 92, 91, 90, 0, 77, 25, 30, 79, 82, 70,
73, 57, 52, 47, 101, 101, 78, 101, 101, 101, 75, 77, 61, 56, 51, 108, 108, 87, 81, 108,
0, 63, 0, 58, 65, 54, 69, 54, 67, 55, 108, 108, 0, 66, 0, 61, 68, 57, 72, 57,
59, 41, 36, 101, 55, 0, 52, 57, 41, 43, 70, 58, 62, 44, 39, 108, 74, 108, 57, 0,
43, 37, 48, 29, 32, 0, 33, 38, 47, 37, 54, 59, 43, 45, 45, 39, 50, 31, 34, 0,
45, 34, 43, 24, 0, 32, 0, 31, 33, 0, 35, 40, 49, 39, 47, 36, 45, 26, 0, 34,
27, 0, 24, 25, 0, 37, 29, 0, 21, 30, 0, 33, 35, 0, 29, 0, 24, 25, 0, 37,
29, 0, 0, 101, 39 29, 0, 21, 30, 29, 0, 0, 108, 41, 52
} ; } ;
static yyconst short int yy_def[86] = static yyconst short int yy_def[91] =
{ 0, { 0,
84, 1, 84, 84, 84, 84, 84, 84, 84, 84, 88, 1, 88, 88, 88, 88, 88, 88, 88, 88,
84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89,
85, 85, 85, 84, 84, 84, 84, 84, 84, 84, 89, 89, 89, 89, 88, 88, 88, 90, 88, 88,
85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89,
85, 85, 85, 84, 85, 85, 85, 85, 85, 85, 89, 89, 89, 89, 89, 88, 90, 88, 89, 89,
85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89,
85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89,
85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89,
85, 85, 85, 0, 84 89, 89, 89, 89, 89, 89, 89, 0, 88, 88
} ; } ;
static yyconst short int yy_nxt[140] = static yyconst short int yy_nxt[149] =
{ 0, { 0,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12,
14, 13, 13, 13, 13, 15, 13, 16, 13, 13, 13, 14, 15, 14, 14, 14, 14, 16, 14, 17,
17, 18, 19, 20, 13, 13, 21, 13, 13, 13, 14, 14, 18, 19, 20, 21, 14, 14, 22, 14,
13, 22, 13, 13, 13, 23, 13, 24, 33, 35, 14, 14, 14, 23, 14, 14, 14, 24, 14, 25,
31, 83, 82, 34, 81, 80, 79, 78, 77, 36, 35, 37, 33, 87, 86, 36, 85, 84, 83, 82,
76, 75, 74, 73, 65, 72, 71, 70, 69, 68, 81, 38, 47, 47, 80, 79, 78, 77, 69, 76,
67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66,
57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 65, 64, 63, 62, 61, 60, 48, 59, 58, 57,
47, 46, 45, 27, 44, 43, 42, 41, 40, 39, 56, 55, 54, 53, 52, 51, 50, 49, 29, 48,
38, 37, 32, 30, 29, 28, 27, 26, 25, 84, 46, 45, 44, 43, 42, 41, 40, 39, 34, 32,
3, 84, 84, 84, 84, 84, 84, 84, 84, 84, 31, 30, 29, 28, 27, 26, 88, 3, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
88, 88, 88, 88, 88, 88, 88, 88
} ; } ;
static yyconst short int yy_chk[140] = static yyconst short int yy_chk[149] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 15, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
85, 81, 80, 15, 79, 77, 76, 74, 73, 16, 16, 17, 89, 85, 84, 16, 83, 81, 80, 78,
71, 69, 68, 66, 64, 63, 62, 61, 60, 59, 77, 17, 90, 90, 75, 73, 72, 70, 68, 67,
58, 57, 55, 54, 53, 52, 51, 50, 49, 48, 66, 65, 64, 63, 62, 61, 59, 58, 57, 56,
47, 45, 43, 42, 41, 40, 39, 38, 37, 36, 55, 54, 53, 52, 51, 49, 47, 45, 44, 43,
35, 34, 32, 27, 24, 23, 22, 21, 20, 19, 42, 41, 40, 39, 38, 37, 36, 34, 29, 28,
18, 17, 14, 12, 11, 10, 9, 8, 6, 3, 25, 24, 23, 22, 21, 20, 19, 18, 15, 13,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 12, 11, 10, 9, 8, 6, 3, 88, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
84, 84, 84, 84, 84, 84, 84, 84, 84 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
88, 88, 88, 88, 88, 88, 88, 88
} ; } ;
static yy_state_type yy_last_accepting_state; static yy_state_type yy_last_accepting_state;
...@@ -429,7 +431,7 @@ char *yytext; ...@@ -429,7 +431,7 @@ char *yytext;
#define fileno _fileno #define fileno _fileno
#line 433 "Lexer.c" #line 435 "Lexer.c"
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
...@@ -584,7 +586,7 @@ YY_DECL ...@@ -584,7 +586,7 @@ YY_DECL
#line 588 "Lexer.c" #line 590 "Lexer.c"
if ( yy_init ) if ( yy_init )
{ {
...@@ -635,13 +637,13 @@ yy_match: ...@@ -635,13 +637,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 85 ) if ( yy_current_state >= 89 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_base[yy_current_state] != 101 ); while ( yy_base[yy_current_state] != 108 );
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
...@@ -834,15 +836,20 @@ YY_RULE_SETUP ...@@ -834,15 +836,20 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 132 "Lexer.l" #line 131 "Lexer.l"
{ } {}
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 134 "Lexer.l" #line 133 "Lexer.l"
{ }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 135 "Lexer.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 846 "Lexer.c" #line 853 "Lexer.c"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
yyterminate(); yyterminate();
...@@ -1134,7 +1141,7 @@ static yy_state_type yy_get_previous_state() ...@@ -1134,7 +1141,7 @@ static yy_state_type yy_get_previous_state()
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 85 ) if ( yy_current_state >= 89 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
...@@ -1169,11 +1176,11 @@ yy_state_type yy_current_state; ...@@ -1169,11 +1176,11 @@ yy_state_type yy_current_state;
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 85 ) if ( yy_current_state >= 89 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 84); yy_is_jam = (yy_current_state == 88);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
...@@ -1728,5 +1735,5 @@ int main() ...@@ -1728,5 +1735,5 @@ int main()
return 0; return 0;
} }
#endif #endif
#line 134 "Lexer.l" #line 135 "Lexer.l"
...@@ -128,6 +128,7 @@ TMP { ...@@ -128,6 +128,7 @@ TMP {
return yytext[0]; return yytext[0];
} }
"//".*\n {}
[ \t\n] { } [ \t\n] { }
......
"C:\StudiaCd\Inżynierka\GameCompiler\Grammar\tools\bin\flex" -oLexer.c Lexer.l && set PATH=C:\StudiaCd\Inżynierka\GameCompiler\Grammar\tools\bin;%PATH% && bison -d Parser.y "C:\Jakub\StudiaInf\Inzynierka\GameCompiler\Grammar\tools\bin\flex" -oLexer.c Lexer.l && set PATH=C:\Jakub\StudiaInf\Inzynierka\GameCompiler\Grammar\tools\bin;%PATH% && bison -d Parser.y
\ No newline at end of file \ No newline at end of file
...@@ -41,9 +41,9 @@ MOVES ...@@ -41,9 +41,9 @@ MOVES
{ {
IF(#.amount <= 0) { RETURN false; } IF(#.amount <= 0) { RETURN false; }
IF(#.stack == 0 && #.amount <= $.a && #.amount > 0) { RETURN true; } IF(#.stack == 0 && #.amount <= $.a) { RETURN true; } // Comment
IF(#.stack == 1 && #.amount <= $.b && #.amount > 0) { RETURN true; } IF(#.stack == 1 && #.amount <= $.b) { RETURN true; }
IF(#.stack == 2 && #.amount <= $.c && #.amount > 0) { RETURN true; } IF(#.stack == 2 && #.amount <= $.c) { RETURN true; }
RETURN false; RETURN false;
}) })
[] []
......
PLAYERS
[
owca[1];
wilki[1];
]
STATE
[
INT o_x = 3;
INT o_y = 7;
INT w0_x = 0;
INT w0_y = 0;
INT w1_x = 2;
INT w1_y = 0;
INT w2_x = 4;
INT w2_y = 0;
INT w3_x = 6;
INT w3_y = 0;
]
([]{})
MAIN_RULE
[
o
([]
{
IF($.o_y == 0)
{
RETURN true;
}
RETURN false;
})
owca
[]{ RETURN 1; }
wilki
[]{ RETURN -1; }
%
w
([
INT move_x = 0;
INT move_y = 0;
]
{
move_x = $.o_x - 1;
move_y = $.o_y - 1;
IF ( move_x >= 0 && move_y >= 0 &&
(move_x != $.w0_x || move_y != $.w0_y) &&
(move_x != $.w1_x || move_y != $.w1_y) &&
(move_x != $.w2_x || move_y != $.w2_y) &&
(move_x != $.w3_x || move_y != $.w3_y))
{ RETURN false; }
move_x = $.o_x - 1;
move_y = $.o_y + 1;
IF ( move_x >= 0 && move_y <= 7 &&
(move_x != $.w0_x || move_y != $.w0_y) &&
(move_x != $.w1_x || move_y != $.w1_y) &&
(move_x != $.w2_x || move_y != $.w2_y) &&
(move_x != $.w3_x || move_y != $.w3_y))
{ RETURN false; }
move_x = $.o_x + 1;
move_y = $.o_y - 1;
IF ( move_x <= 7 && move_y >= 0 &&
(move_x != $.w0_x || move_y != $.w0_y) &&
(move_x != $.w1_x || move_y != $.w1_y) &&
(move_x != $.w2_x || move_y != $.w2_y) &&
(move_x != $.w3_x || move_y != $.w3_y))
{ RETURN false; }
move_x = $.o_x + 1;
move_y = $.o_y + 1;
IF ( move_x <= 7 && move_y <= 7 &&
(move_x != $.w0_x || move_y != $.w0_y) &&
(move_x != $.w1_x || move_y != $.w1_y) &&
(move_x != $.w2_x || move_y != $.w2_y) &&
(move_x != $.w3_x || move_y != $.w3_y))
{ RETURN false; }
RETURN true;
})
owca
[]{ RETURN -1; }
wilki
[]{ RETURN 1; }
]
MOVES
[
owca<owca>
[
INT move_x = 0;
INT move_y = 0;
]
([ INT d_x = 0; INT d_y = 0;]
{
d_x = $.o_x - #.move_x;
d_y = $.o_y - #.move_y;
IF((d_x != 1 && d_x != -1) || (d_y != 1 && d_y != -1)) { RETURN false;}
IF ( (#.move_x == $.w0_x && #.move_y == $.w0_y) ||
(#.move_x == $.w1_x && #.move_y == $.w1_y) ||
(#.move_x == $.w2_x && #.move_y == $.w2_y) ||
(#.move_x == $.w3_x && #.move_y == $.w3_y))
{ RETURN false; }
RETURN true;
})
[]
{
$.o_x = #.move_x;
$.o_y = #.move_y;
& = wilki[0];
}
%
wilki<wilki>
[
INT wilk_indeks = 0;
INT move_x = 0;
INT move_y = 0;
]
([ INT wilk_x = 0; INT wilk_y = 0;
INT d_x = 0; INT d_y = 0;]
{
IF (#.wilk_indeks < 0 || #.wilk_indeks > 3) { RETURN false; }
IF (#.wilk_indeks == 0) { wilk_x = $.w0_x; wilk_y = $.w0_y; }
IF (#.wilk_indeks == 1) { wilk_x = $.w1_x; wilk_y = $.w1_y; }
IF (#.wilk_indeks == 2) { wilk_x = $.w2_x; wilk_y = $.w2_y; }
IF (#.wilk_indeks == 3) { wilk_x = $.w3_x; wilk_y = $.w3_y; }
IF (#.move_y != wilk_y + 1) { RETURN false; }
IF (#.move_x != wilk_x + 1 && #.move_x != wilk_x - 1) { RETURN false; }
IF (#.move_x > 7) { RETURN false; }
IF (#.move_y > 7 || #.move_y < 0) { RETURN false; }
IF (#.move_x == $.o_x && #.move_y == $.o_y) { RETURN false; }
IF (#.move_x == $.w0_x && #.move_y == $.w0_y) { RETURN false; }
IF (#.move_x == $.w1_x && #.move_y == $.w1_y) { RETURN false; }
IF (#.move_x == $.w2_x && #.move_y == $.w2_y) { RETURN false; }
IF (#.move_x == $.w3_x && #.move_y == $.w3_y) { RETURN false; }
RETURN true;
})
[]
{
IF (#.wilk_indeks == 0) { $.w0_x = #.move_x; $.w0_y = #.move_y; }
IF (#.wilk_indeks == 1) { $.w1_x = #.move_x; $.w1_y = #.move_y; }
IF (#.wilk_indeks == 2) { $.w2_x = #.move_x; $.w2_y = #.move_y; }
IF (#.wilk_indeks == 3) { $.w3_x = #.move_x; $.w3_y = #.move_y; }
& = owca[0];
}
]
\ No newline at end of file
...@@ -39,14 +39,120 @@ public: ...@@ -39,14 +39,120 @@ public:
} }
}; };
void printBoard(DataSet* board)
{
int o_x = *(int*)board->getValuePtr("o_x");
int o_y = *(int*)board->getValuePtr("o_y");
int w_x[4];
int w_y[4];
for (int i = 0; i < 4; i++) w_x[i] = *(int*)board->getValuePtr("w" + std::to_string(i) + "_x");
for (int i = 0; i < 4; i++) w_y[i] = *(int*)board->getValuePtr("w" + std::to_string(i) + "_y");
for(int j = 7; j >= 0; j--)
{
for (int i = 0; i < 8; i++)
{
if (o_x == i && o_y == j) std::cout << 'O';
else if (w_x[0] == i && w_y[0] == j ||
w_x[1] == i && w_y[1] == j ||
w_x[2] == i && w_y[2] == j ||
w_x[3] == i && w_y[3] == j) std::cout << 'W';
else if (i % 2 == j % 2) std::cout << (char) 219;
else std::cout << ' ';
}
std::cout << '\n';
}
std::cout << "\n\n";
}
class Owca : public IPlayer
{
public:
Owca() {}
std::string makeMove(DataSet* state_data, std::unordered_map<std::string, DataSet*> moves_map) override {
printBoard(state_data);
DataSet* move = moves_map.at("owca");
int x, y;
std::cout << "X: ";
std::cin >> x;
std::cout << "Y: ";
std::cin >> y;
move->setInt("move_x", x);
move->setInt("move_y", y);
std::cout << "\n\n";
return "owca";
}
void Payoff(int payoff) override {
std::cout << "Owca: " << payoff << '\n';
}
};
class Wilki : public IPlayer
{
public:
Wilki() {}
std::string makeMove(DataSet* state_data, std::unordered_map<std::string, DataSet*> moves_map) override {
printBoard(state_data);
DataSet* move = moves_map.at("wilki");
int index, x, y;
std::cout << "Wilk: ";
std::cin >> index;
std::cout << "X: ";
std::cin >> x;
std::cout << "Y: ";
std::cin >> y;
move->setInt("wilk_indeks", index);
move->setInt("move_x", x);
move->setInt("move_y", y);
std::cout << "\n\n";
return "wilki";
}
void Payoff(int payoff) override {
std::cout << "Owca: " << payoff << '\n';
}
};
void wioTest()
{
Owca* owca = new Owca();
Wilki* wilki = new Wilki();
Game* game = Compiler().createGame("Source/wio.txt");
game->setPlayer(owca, "owca", 0);
game->setPlayer(wilki, "wilki", 0);
game->startGame();
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
/*/
wioTest();
/*/
consolePlayer* player_a = new consolePlayer("a"); consolePlayer* player_a = new consolePlayer("a");
consolePlayer* player_b = new consolePlayer("b"); consolePlayer* player_b = new consolePlayer("b");
Game* game = Compiler().createGame("Source/source.txt"); Game* game = Compiler().createGame("Source/source.txt");
game->setPlayer(player_a, "player", 0); game->setPlayer(player_a, "player", 0);
game->setPlayer(player_b, "player", 1); game->setPlayer(player_b, "player", 1);
game->startGame(); game->startGame();
//*/
return 0; return 0;
} }
\ No newline at end of file