#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "word.h"
#include "parse.h"

Command *parse(Game *g, const char *typed_command) {
  Command *c = malloc(sizeof(Command));
  for (int i = 0; i < MAX_WORDS_IN_COMMAND; i++) {
    c->words[i] = NULL;
  }

  char *bluh = malloc(strlen(typed_command) + 1);
  strcpy(bluh, typed_command);

  int word_count = 0;
  char *token = strtok(bluh, " ");

  while (word_count < MAX_WORDS_IN_COMMAND && token != NULL) {
    c->words[word_count] = find_word(g->words, token);

    word_count++;
    token = strtok(NULL, " ");
  }

  free(bluh);
  return c;
}
