Merge branch 'master' of https://github.tamu.edu/brj2013/Breakthrough
This commit is contained in:
commit
5cfb44a1dd
2 changed files with 160 additions and 96 deletions
73
Client.java
73
Client.java
|
@ -309,16 +309,30 @@ public class Client {
|
||||||
frame.setMinimumSize(frame.getSize());
|
frame.setMinimumSize(frame.getSize());
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
//userInput = stdIn.readLine();
|
//userInput = stdIn.readLine();
|
||||||
|
<<<<<<< HEAD
|
||||||
|
int gameMode = 0;
|
||||||
|
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||||
|
gameMode = Integer.parseInt(userInput);
|
||||||
|
while(!userInput.equals("1") && !userInput.equals("2")) {
|
||||||
|
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||||
|
output.println(userInput);
|
||||||
|
}
|
||||||
|
gameMode = Integer.parseInt(userInput);
|
||||||
|
=======
|
||||||
userInput = JOptionPane.showInputDialog(frame, temp);
|
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||||
//while(!userInput.contains("1") || !userInput.contains("2")) {
|
//while(!userInput.contains("1") || !userInput.contains("2")) {
|
||||||
// userInput = JOptionPane.showInputDialog(frame, temp);
|
// userInput = JOptionPane.showInputDialog(frame, temp);
|
||||||
//}
|
//}
|
||||||
|
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||||
output.println(userInput);
|
output.println(userInput);
|
||||||
|
|
||||||
String diff = "?";
|
String diff = "?";
|
||||||
in.read(b, 0, 256);
|
in.read(b, 0, 256);
|
||||||
temp = String.valueOf(b).trim();
|
temp = String.valueOf(b).trim();
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
//System.out.print(temp);
|
//System.out.print(temp);
|
||||||
|
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||||
while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
|
while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
|
||||||
diff = JOptionPane.showInputDialog(frame, temp);//diff = stdIn.readLine();
|
diff = JOptionPane.showInputDialog(frame, temp);//diff = stdIn.readLine();
|
||||||
diff = diff.toUpperCase();
|
diff = diff.toUpperCase();
|
||||||
|
@ -328,7 +342,9 @@ public class Client {
|
||||||
}
|
}
|
||||||
output.println(userInput);
|
output.println(userInput);
|
||||||
String out = "";
|
String out = "";
|
||||||
|
<<<<<<< HEAD
|
||||||
|
if(gameMode == 1)
|
||||||
|
{
|
||||||
while(!end) {
|
while(!end) {
|
||||||
char[] buffer = new char[256];
|
char[] buffer = new char[256];
|
||||||
in.read(buffer, 0, 256);
|
in.read(buffer, 0, 256);
|
||||||
|
@ -357,6 +373,17 @@ public class Client {
|
||||||
System.out.println("Invalid move.");
|
System.out.println("Invalid move.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
|
||||||
|
while(!end) {
|
||||||
|
char[] buffer = new char[256];
|
||||||
|
in.read(buffer, 0, 256);
|
||||||
|
for(int i = 0; i < buffer.length; ++i) {
|
||||||
|
if(Arrays.equals(Arrays.copyOfRange(buffer, i, i+9), go)) {
|
||||||
|
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||||
|
JOptionPane.showMessageDialog(null, "\nGAME OVER\n");
|
||||||
|
end = true;
|
||||||
|
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||||
}
|
}
|
||||||
System.out.println(out);
|
System.out.println(out);
|
||||||
output.println(out);
|
output.println(out);
|
||||||
|
@ -368,6 +395,50 @@ public class Client {
|
||||||
stdIn.close();
|
stdIn.close();
|
||||||
echoSocket.close();
|
echoSocket.close();
|
||||||
}
|
}
|
||||||
|
if(gameMode == 2)
|
||||||
|
{
|
||||||
|
while(!end) {
|
||||||
|
char[] buffer = new char[256];
|
||||||
|
in.read(buffer, 0, 256);
|
||||||
|
for(int i = 0; i < buffer.length; ++i) {
|
||||||
|
if(Arrays.equals(Arrays.copyOfRange(buffer, i, i+9), go)) {
|
||||||
|
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||||
|
JOptionPane.showMessageDialog(null, "\nGAME OVER\n");
|
||||||
|
end = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(String.valueOf(buffer).trim());
|
||||||
|
window.updateBoard(String.valueOf(buffer).trim());
|
||||||
|
/*
|
||||||
|
while(!end && boardoutput.length() < 4) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
if(!undoString.equals("")) {
|
||||||
|
System.out.println(undoString);
|
||||||
|
//output.println(undoString);
|
||||||
|
//output.flush();
|
||||||
|
undoString = "";
|
||||||
|
}
|
||||||
|
if(boardoutput.length() == 4) {
|
||||||
|
out = parseOutput(boardoutput);
|
||||||
|
if(out == "Invalid") {
|
||||||
|
out = "";
|
||||||
|
boardoutput = "";
|
||||||
|
System.out.println("Invalid move.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
System.out.println(out);
|
||||||
|
//output.println(out);
|
||||||
|
//output.flush();
|
||||||
|
boardoutput = "";
|
||||||
|
}
|
||||||
|
output.close();
|
||||||
|
in.close();
|
||||||
|
stdIn.close();
|
||||||
|
echoSocket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (IOException e){
|
catch (IOException e){
|
||||||
System.err.println("IOException: " + e.getMessage());
|
System.err.println("IOException: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
69
Server.cpp
69
Server.cpp
|
@ -19,44 +19,6 @@ void error(const char *msg)
|
||||||
perror(msg);
|
perror(msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
string tempParse(string move) {
|
|
||||||
string output = "";
|
|
||||||
int tempa = move[0] - '0';
|
|
||||||
int tempb = move[1] - '0';
|
|
||||||
int tempc = move[2] - '0';
|
|
||||||
int tempd = move[3] - '0';
|
|
||||||
|
|
||||||
//cout << "move: " << move << " " << tempa << " " << tempb << " " << tempc << " " << tempd << "\n";
|
|
||||||
|
|
||||||
for(int c = 0; c < 4; c++) {
|
|
||||||
if(!isdigit(move[c])) {
|
|
||||||
//cout << "\nfjdkjfjd\n";
|
|
||||||
if(move.substr(0, 4) == "UNDO") {
|
|
||||||
return "UNDO";
|
|
||||||
}
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(tempa == (tempc + 1)) {
|
|
||||||
//cout << "\nTest\n";
|
|
||||||
if(tempb == tempd) {
|
|
||||||
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_f";
|
|
||||||
}
|
|
||||||
else if(tempb == (tempd + 1)) {
|
|
||||||
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_l";
|
|
||||||
}
|
|
||||||
else if(tempb == (tempd - 1)) {
|
|
||||||
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_r";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
cout << "Debugging: " << output << "\n\n";
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -134,6 +96,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
|
if(choice == 1)
|
||||||
|
{
|
||||||
while(gameOver != true)
|
while(gameOver != true)
|
||||||
{
|
{
|
||||||
gameOver = e.getBoard()->isGameOver();
|
gameOver = e.getBoard()->isGameOver();
|
||||||
|
@ -175,6 +139,35 @@ int main(int argc, char *argv[])
|
||||||
e.getBoard()->setValidFalse();
|
e.getBoard()->setValidFalse();
|
||||||
e.getBoard()->snapshot(record, *e.getBoard());
|
e.getBoard()->snapshot(record, *e.getBoard());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(choice == 2)
|
||||||
|
{
|
||||||
|
while (gameOver != true) {
|
||||||
|
gameOver = e.getBoard()->isGameOver();
|
||||||
|
|
||||||
|
while(e.getBoard()->getTurn() == 'O') {
|
||||||
|
e.getBoard()->displayBoard();//Display the board on the server
|
||||||
|
string boardState = e.getBoard()->boardToString();
|
||||||
|
final_move = e.getBoard()->boardToString();
|
||||||
|
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||||
|
e.AI(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.getBoard()->displayBoard();
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
while(e.getBoard()->getTurn() == 'X' ) {
|
||||||
|
e.getBoard()->displayBoard();//Display the board on the server
|
||||||
|
string boardState = e.getBoard()->boardToString();
|
||||||
|
final_move = e.getBoard()->boardToString();
|
||||||
|
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||||
|
e.AI(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameOver = e.getBoard()->isGameOver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final_move = e.getBoard()->boardToString();
|
final_move = e.getBoard()->boardToString();
|
||||||
string game_over = "\n\nGAME OVER!!!\n";
|
string game_over = "\n\nGAME OVER!!!\n";
|
||||||
|
|
Reference in a new issue