change to final_test

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

Fork of Fianl_test by Hongyao Shi

Committer:
honelight
Date:
Mon Apr 20 23:05:36 2015 +0000
Revision:
0:28f8ba171e86
Child:
3:b834ab4a53d1
test program, still doesn't work;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
honelight 0:28f8ba171e86 1 #include "stdio.h"
honelight 0:28f8ba171e86 2 #include "stdlib.h"
honelight 0:28f8ba171e86 3 #include "board.h"
honelight 0:28f8ba171e86 4
honelight 0:28f8ba171e86 5
honelight 0:28f8ba171e86 6
honelight 0:28f8ba171e86 7 Board::Board(void)
honelight 0:28f8ba171e86 8 {
honelight 0:28f8ba171e86 9 board = new int*[3];
honelight 0:28f8ba171e86 10 for(int i=0; i<3; i++)
honelight 0:28f8ba171e86 11 {
honelight 0:28f8ba171e86 12 board[i] = new int[3];
honelight 0:28f8ba171e86 13 for(int j=0; j<3; j++)
honelight 0:28f8ba171e86 14 board[i][j]=0;
honelight 0:28f8ba171e86 15 }
honelight 0:28f8ba171e86 16 }
honelight 0:28f8ba171e86 17
honelight 0:28f8ba171e86 18 int ** Board::get_board()
honelight 0:28f8ba171e86 19 {
honelight 0:28f8ba171e86 20 return board;
honelight 0:28f8ba171e86 21 }
honelight 0:28f8ba171e86 22
honelight 0:28f8ba171e86 23 void Board::set_board(int col, int row, int playerID)
honelight 0:28f8ba171e86 24 {
honelight 0:28f8ba171e86 25 if(board[col][row]!=0 && turn == playerID)
honelight 0:28f8ba171e86 26 {}
honelight 0:28f8ba171e86 27 else
honelight 0:28f8ba171e86 28 {
honelight 0:28f8ba171e86 29 board[col][row] = playerID;
honelight 0:28f8ba171e86 30 }
honelight 0:28f8ba171e86 31 }
honelight 0:28f8ba171e86 32
honelight 0:28f8ba171e86 33 bool Board::updateBoard(int turn, int printout)
honelight 0:28f8ba171e86 34 {
honelight 0:28f8ba171e86 35 int location_x = printout/3;
honelight 0:28f8ba171e86 36 int location_y = printout%3;
honelight 0:28f8ba171e86 37 if(board[location_x][location_y] == 0)
honelight 0:28f8ba171e86 38 {
honelight 0:28f8ba171e86 39 board[location_x][location_y] = turn;
honelight 0:28f8ba171e86 40 return true;
honelight 0:28f8ba171e86 41 }
honelight 0:28f8ba171e86 42 else
honelight 0:28f8ba171e86 43 return false;
honelight 0:28f8ba171e86 44 }
honelight 0:28f8ba171e86 45
honelight 0:28f8ba171e86 46 int Board::updateBoard_output(int turn, int printout)
honelight 0:28f8ba171e86 47 {
honelight 0:28f8ba171e86 48 int location_x = printout/3;
honelight 0:28f8ba171e86 49 int location_y = printout%3;
honelight 0:28f8ba171e86 50 return board[location_x][location_y];
honelight 0:28f8ba171e86 51 }
honelight 0:28f8ba171e86 52
honelight 0:28f8ba171e86 53
honelight 0:28f8ba171e86 54 int Board::check_victory(int playerID)
honelight 0:28f8ba171e86 55 {
honelight 0:28f8ba171e86 56 if(board[0][0] == playerID && board[0][1] == playerID && board[0][2] == playerID
honelight 0:28f8ba171e86 57 ||board[0][0] == playerID && board[1][1] == playerID && board[2][2] == playerID
honelight 0:28f8ba171e86 58 ||board[0][0] == playerID && board[1][0] == playerID && board[2][0] == playerID
honelight 0:28f8ba171e86 59 ||board[1][0] == playerID && board[1][1] == playerID && board[1][2] == playerID
honelight 0:28f8ba171e86 60 ||board[2][0] == playerID && board[2][1] == playerID && board[2][2] == playerID
honelight 0:28f8ba171e86 61 ||board[0][1] == playerID && board[1][1] == playerID && board[1][2] == playerID
honelight 0:28f8ba171e86 62 ||board[0][1] == playerID && board[2][1] == playerID && board[2][2] == playerID
honelight 0:28f8ba171e86 63 ||board[0][2] == playerID && board[1][1] == playerID && board[2][0] == playerID)
honelight 0:28f8ba171e86 64 return playerID;
honelight 0:28f8ba171e86 65 else
honelight 0:28f8ba171e86 66 return 0;
honelight 0:28f8ba171e86 67 }
honelight 0:28f8ba171e86 68
honelight 0:28f8ba171e86 69