Implementation of your "Fury of Dracula" Dracula AI

C Program to Implementation of your "Fury of Dracula" Dracula AI in C Programming Language ?

Solution:
// Implementation of your "Fury of Dracula" Dracula AI
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include "Game.h"
#include "DracView.h"
#include "GameView.h"
#include "stack.h"

int inArr(LocationID arr[], int n, LocationID city);

void decideDraculaMove(DracView gameState)
{
assert (gameState != NULL);
// Starting turn
if (whereIs(gameState, PLAYER_DRACULA) == -1) {
registerBestPlay("CD", "turn 1 lmao");
return;
}
/*
* Depth first search through the paths we can take.
* This will go down to a certain depth and give each path a score.
* The scoring is to allow for future decision criteria, but for now we will
* give every path a score of 1 if it can be taken, 0 if it cannot be taken.
*
*/
// Locations we can immediately move to
// Note that locations[0] is our current location.
int numLocs;
LocationID *locations = whereCanIgo(gameState, &numLocs, 1, 1);
// Grab the trail from the game engine
// as well as some useful stats, like round number
LocationID myTrail[TRAIL_SIZE];
giveMeTheTrail(gameState, PLAYER_DRACULA, myTrail);
Round round = giveMeTheRound(gameState);

// Search to depth 2
int searchDepth = 2;
int visited[NUM_MAP_LOCATIONS] = {0};
int scores[NUM_MAP_LOCATIONS]  = {0};
int currInd = 1;
int currDepth = 0;
Stack s = newStack();
pushOnto(s, locations[currInd]);
while (!emptyStack(s)) {
LocationID curr = popFrom(s);
// check whether curr is in the Trail already
if (inArr(myTrail, TRAIL_SIZE, curr)) {
scores[curr] = 0;
}
// Get the neighbours of curr
int numNeighbours;
LocationID neighbours = connectedLocations((GameView)gameState, &numNeighbours,
curr, PLAYER_DRACULA, round,
TRUE, FALSE, TRUE);
for (n = 1; n < numNeighbours; n++) {
pushOnto(s, neighbours[n]);
}
}
}


int inArr(LocationID arr[], int n, LocationID city)
{
int i;
for (i = 0; i < n; i++) {
if (arr[i] == city) return 1;
}
return 0;
}


Learn More :