#include "computer_player.h"
#include <stdlib.h>
#include <stdio.h>
#include <resources/battclock.h>
#include <clib/exec_protos.h>
#include <clib/battclock_protos.h>
/*
**  Inputs:
**          skill_level     1 being the lowest skill level
**                          1 being the highest skill level
**          filled          2D array describing gameboard contents
**          columntop
**
**  Result:
**          Computer player's choice of column in which to place piece
**          -1 on error
*/
APTR BattClockBase=NULL;

int computer_player (int skill_level, char **filled, char *columntop, BOOL newgame)
{
    enum {ERROR=-1};

    if (BattClockBase=OpenResource(BATTCLOCKNAME))
    {
        if (newgame)
            srand(ReadBattClock()); // Seed the random generator with the system clock
                                    // to ensure the moves are different each time
        switch (skill_level)
        {
            // just needs columntop
            case 1:
            {
                int result;
                BOOL badmove=TRUE;

                while (badmove)
                {
                    result=rand();
                    result-=(result/7)*7;
                    if (columntop[result]!=4)
                        badmove=FALSE;
                }

                return result;
            }

            default:
                return ERROR;
        }
    }

    return ERROR;
}
/*
int main (void)
{
    int i;

    printf("%d ", computer_player(1, NULL, NULL, TRUE));
    for (i=0; i<19; i++)
        printf("%d ", computer_player(1, NULL, NULL, FALSE));

    puts("");

    return 0;
}
*/
