A complete game turn script demonstrating multiple DSL commands for moving, gaining resources, and drawing cards.
ID: 1386
using uCalcSoftware;
var uc = new uCalc();
// 1. Define the initial game state
uc.DefineVariable("p1_pos = 0");
uc.DefineVariable("p1_gold = 10");
uc.DefineVariable("p2_pos = 0");
uc.DefineVariable("p2_gold = 10");
// 2. Define the DSL rules
var t = uc.ExpressionTransformer;
t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}");
t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}");
// 3. Define the script for the turn
var game_turn_script = """
PLAYER 1 MOVES 4
PLAYER 2 MOVES 2
PLAYER 1 GAINS 5 GOLD
PLAYER 2 MOVES 3
""";
// 4. Execute the script
uc.EvalStr(game_turn_script);
// 5. Display the final state
Console.WriteLine("--- End of Turn State ---");
Console.WriteLine($"Player 1 Position: {uc.EvalStr("p1_pos")}");
Console.WriteLine($"Player 1 Gold: {uc.EvalStr("p1_gold")}");
Console.WriteLine($"Player 2 Position: {uc.EvalStr("p2_pos")}");
Console.WriteLine($"Player 2 Gold: {uc.EvalStr("p2_gold")}");
--- End of Turn State ---
Player 1 Position: 4
Player 1 Gold: 15
Player 2 Position: 5
Player 2 Gold: 10 using uCalcSoftware; var uc = new uCalc(); // 1. Define the initial game state uc.DefineVariable("p1_pos = 0"); uc.DefineVariable("p1_gold = 10"); uc.DefineVariable("p2_pos = 0"); uc.DefineVariable("p2_gold = 10"); // 2. Define the DSL rules var t = uc.ExpressionTransformer; t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}"); t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}"); // 3. Define the script for the turn var game_turn_script = """ PLAYER 1 MOVES 4 PLAYER 2 MOVES 2 PLAYER 1 GAINS 5 GOLD PLAYER 2 MOVES 3 """; // 4. Execute the script uc.EvalStr(game_turn_script); // 5. Display the final state Console.WriteLine("--- End of Turn State ---"); Console.WriteLine($"Player 1 Position: {uc.EvalStr("p1_pos")}"); Console.WriteLine($"Player 1 Gold: {uc.EvalStr("p1_gold")}"); Console.WriteLine($"Player 2 Position: {uc.EvalStr("p2_pos")}"); Console.WriteLine($"Player 2 Gold: {uc.EvalStr("p2_gold")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// 1. Define the initial game state
uc.DefineVariable("p1_pos = 0");
uc.DefineVariable("p1_gold = 10");
uc.DefineVariable("p2_pos = 0");
uc.DefineVariable("p2_gold = 10");
// 2. Define the DSL rules
auto t = uc.ExpressionTransformer();
t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}");
t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}");
// 3. Define the script for the turn
auto game_turn_script = R"(
PLAYER 1 MOVES 4
PLAYER 2 MOVES 2
PLAYER 1 GAINS 5 GOLD
PLAYER 2 MOVES 3
)";
// 4. Execute the script
uc.EvalStr(game_turn_script);
// 5. Display the final state
cout << "--- End of Turn State ---" << endl;
cout << "Player 1 Position: " << uc.EvalStr("p1_pos") << endl;
cout << "Player 1 Gold: " << uc.EvalStr("p1_gold") << endl;
cout << "Player 2 Position: " << uc.EvalStr("p2_pos") << endl;
cout << "Player 2 Gold: " << uc.EvalStr("p2_gold") << endl;
}
--- End of Turn State ---
Player 1 Position: 4
Player 1 Gold: 15
Player 2 Position: 5
Player 2 Gold: 10 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // 1. Define the initial game state uc.DefineVariable("p1_pos = 0"); uc.DefineVariable("p1_gold = 10"); uc.DefineVariable("p2_pos = 0"); uc.DefineVariable("p2_gold = 10"); // 2. Define the DSL rules auto t = uc.ExpressionTransformer(); t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}"); t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}"); // 3. Define the script for the turn auto game_turn_script = R"( PLAYER 1 MOVES 4 PLAYER 2 MOVES 2 PLAYER 1 GAINS 5 GOLD PLAYER 2 MOVES 3 )"; // 4. Execute the script uc.EvalStr(game_turn_script); // 5. Display the final state cout << "--- End of Turn State ---" << endl; cout << "Player 1 Position: " << uc.EvalStr("p1_pos") << endl; cout << "Player 1 Gold: " << uc.EvalStr("p1_gold") << endl; cout << "Player 2 Position: " << uc.EvalStr("p2_pos") << endl; cout << "Player 2 Gold: " << uc.EvalStr("p2_gold") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// 1. Define the initial game state
uc.DefineVariable("p1_pos = 0")
uc.DefineVariable("p1_gold = 10")
uc.DefineVariable("p2_pos = 0")
uc.DefineVariable("p2_gold = 10")
'// 2. Define the DSL rules
Dim t = uc.ExpressionTransformer
t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}")
t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}")
'// 3. Define the script for the turn
Dim game_turn_script = "
PLAYER 1 MOVES 4
PLAYER 2 MOVES 2
PLAYER 1 GAINS 5 GOLD
PLAYER 2 MOVES 3
"
'// 4. Execute the script
uc.EvalStr(game_turn_script)
'// 5. Display the final state
Console.WriteLine("--- End of Turn State ---")
Console.WriteLine($"Player 1 Position: {uc.EvalStr("p1_pos")}")
Console.WriteLine($"Player 1 Gold: {uc.EvalStr("p1_gold")}")
Console.WriteLine($"Player 2 Position: {uc.EvalStr("p2_pos")}")
Console.WriteLine($"Player 2 Gold: {uc.EvalStr("p2_gold")}")
End Sub
End Module
--- End of Turn State ---
Player 1 Position: 4
Player 1 Gold: 15
Player 2 Position: 5
Player 2 Gold: 10 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// 1. Define the initial game state uc.DefineVariable("p1_pos = 0") uc.DefineVariable("p1_gold = 10") uc.DefineVariable("p2_pos = 0") uc.DefineVariable("p2_gold = 10") '// 2. Define the DSL rules Dim t = uc.ExpressionTransformer t.FromTo("PLAYER {@Number:p} MOVES {@Number:n}", "p{p}_pos = p{p}_pos + {n}") t.FromTo("PLAYER {@Number:p} GAINS {@Number:n} GOLD", "p{p}_gold = p{p}_gold + {n}") '// 3. Define the script for the turn Dim game_turn_script = " PLAYER 1 MOVES 4 PLAYER 2 MOVES 2 PLAYER 1 GAINS 5 GOLD PLAYER 2 MOVES 3 " '// 4. Execute the script uc.EvalStr(game_turn_script) '// 5. Display the final state Console.WriteLine("--- End of Turn State ---") Console.WriteLine($"Player 1 Position: {uc.EvalStr("p1_pos")}") Console.WriteLine($"Player 1 Gold: {uc.EvalStr("p1_gold")}") Console.WriteLine($"Player 2 Position: {uc.EvalStr("p2_pos")}") Console.WriteLine($"Player 2 Gold: {uc.EvalStr("p2_gold")}") End Sub End Module