change to final_test

Dependencies:   4DGL-uLCD-SE EthernetInterface HTTPClient mbed-rtos mbed

Fork of Fianl_test by Hongyao Shi

board.cpp

Committer:
jderiso2
Date:
2015-05-01
Revision:
4:e928ee72a948
Parent:
3:b834ab4a53d1

File content as of revision 4:e928ee72a948:

#include "stdio.h"
#include "stdlib.h"
#include "board.h"



Board::Board(void)
{
    board = new int*[3];
    for(int i=0; i<3; i++)
    {
        board[i] = new int[3];
        for(int j=0; j<3; j++)
            board[i][j]=-1;
    }
}

int ** Board::get_board()
{
    return board;
}

void Board::set_board(int col, int row, int playerID)
{
    if(board[col][row]!=0 && turn == playerID)
    {}
    else
    {
        board[col][row] = playerID;
    }
}

bool Board::updateBoard(int turn, int printout)
{
    int location_x = printout/3;
    int location_y = printout%3;
    if(board[location_x][location_y] == 0)
    {
        board[location_x][location_y] = turn;
        return true;
    }
    else
        return false;
}

int Board::updateBoard_output(int turn, int printout)
{
    int location_x = printout/3;
    int location_y = printout%3;
    return board[location_x][location_y];
}


int Board::check_victory(int playerID)
{
    if(board[0][0] == playerID && board[0][1] == playerID && board[0][2] == playerID
    ||board[0][0] == playerID && board[1][1] == playerID && board[2][2] == playerID
    ||board[0][0] == playerID && board[1][0] == playerID && board[2][0] == playerID
    ||board[1][0] == playerID && board[1][1] == playerID && board[1][2] == playerID
    ||board[2][0] == playerID && board[2][1] == playerID && board[2][2] == playerID
    ||board[0][1] == playerID && board[1][1] == playerID && board[1][2] == playerID
    ||board[0][1] == playerID && board[2][1] == playerID && board[2][2] == playerID
    ||board[0][2] == playerID && board[1][1] == playerID && board[2][0] == playerID)
        return playerID;
    else
        return 0;
}