Skip to content

Commit

Permalink
Merge pull request #1 from SharifAIChallenge/dev
Browse files Browse the repository at this point in the history
Complete README.md
  • Loading branch information
onajafi authored Feb 15, 2020
2 parents 128f016 + 7a73fc0 commit 33884ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Build

After implementing your code in `client/src/AI/AI.cpp`, you may need to build and test it.
Below are the instructions to build and execute the client project in different operating systems.

### Unix-Like (Ubuntu, MacOS)

To fetch and build the project use the following commands:
Expand All @@ -14,6 +17,9 @@ mkdir build
cd build
cmake ..
make
# To run the code
./client/client
```

After making any changes to any file just run `make` again.
Expand Down
23 changes: 17 additions & 6 deletions client/src/AI/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
using namespace std;

//Some global variable(s) to access in different turns:
const Path* pathForMyUnits;
int pathIDForMyUnits;

//CAUTION: NEVER DEFINE POINTERS IN THE GLOBAL VARIABLES (BECAUSE
// THE MEMORY OF "World *world" GETS FREED AT THE END OF EVERY TURN
// AND ASSIGNING THAT POINTER TO A PART OF *world IS INCORRECT).
//
// e.g. This wrong:
// const path* pathForMyUnits;
//
// But this is correct:
// int pathIDForMyUnits;
//
// BUT IT'S OK TO DEFINE A POINTER IN THE BELOW FUNCTIONS(pick, turn & end).

void AI::pick(World *world) {
cout << "pick started" << endl;
Expand All @@ -29,8 +41,7 @@ void AI::pick(World *world) {
world->chooseDeck(myDeck);

//other preprocess
pathForMyUnits = world->getFriend()->getPathsFromPlayer()[0];

pathIDForMyUnits = world->getFriend()->getPathsFromPlayer()[0]->getId();
}

void AI::turn(World *world) {
Expand All @@ -41,8 +52,9 @@ void AI::turn(World *world) {

// play all of hand once your ap reaches maximum. if ap runs out, putUnit doesn't do anything
if (myself->getAp() == maxAp) {
for (const BaseUnit *baseUnit : myself->getHand())
world->putUnit(baseUnit, pathForMyUnits);
for (const BaseUnit *baseUnit : myself->getHand()) {
world->putUnit(baseUnit, pathIDForMyUnits);
}
}

// this code tries to cast the received spell
Expand Down Expand Up @@ -73,7 +85,6 @@ void AI::turn(World *world) {
const Path *path = myPaths[rand() % myPaths.size()];
int size = path->getCells().size();
const Cell *cell = path->getCells()[(size + 1) / 2];

world->castUnitSpell(unit, path, cell, receivedSpell);
}
}
Expand Down

0 comments on commit 33884ff

Please sign in to comment.