Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE EthernetInterface HTTPClient mbed-rtos mbed
Fork of Final_test by
board.cpp
- Committer:
- honelight
- Date:
- 2015-04-20
- Revision:
- 0:28f8ba171e86
- Child:
- 3:b834ab4a53d1
File content as of revision 0:28f8ba171e86:
#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]=0;
}
}
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;
}
