Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 15th, 2008, 3:06 PM   #21
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 270
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

yes since that is technically theroot of the problem. Thats where you set input and output sockets twice thus overwritting one socket.

Chris
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 3:13 PM   #22
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

ok i did it and it works but it does the move to that players board not the other do i just need to go into takeTurn and make it so the turn is executed on the other person's board? So in takeTurn1 it would take the turn on b2 and in takeTurn2 it would take the turn on b1?
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:16 PM   #23
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 270
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

yes, thats correct.

Chris
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 3:20 PM   #24
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

i dont know i cant get it to do it. I have takeTurn1 receive b2 and then takeTurn on b2 and then send b2 back but it still does moves on itself i think unless im confusing them or something
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:21 PM   #25
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 270
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

paste that bit of code in and let me have a look
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 3:26 PM   #26
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

i think its in the client that its doing it because when i enter a move on one client it is doing that move on the board that is printed for the client i dont know if in sending and receiving its switching them or something but here is the server takeTurn methods
java Syntax (Toggle Plain Text)
  1. // get the move from the user and take turn for player 1
  2. // player 1 wants to take turn on player 2's board
  3. static void takeTurn1() throws IOException
  4. {
  5. String getRowCol = "Please enter a row and col 0-9 so it looks like this 1,2: ";
  6. int row = 0;
  7. int col = 0;
  8. send((String) getRowCol);
  9. String receivedRowCol = (String) receive();
  10. row = Integer.parseInt(getRow((String) receivedRowCol));
  11. col = Integer.parseInt(getCol((String) receivedRowCol));
  12. String rowColAre = "The row is " + row + "\nThe Col is " + col + "\n";
  13. send((String) rowColAre);
  14. System.out.println("The row is " + row);
  15. System.out.println("The col is " + col);
  16. // take turn on other player's board
  17. b2 = (Board) receive();
  18. p1.takeTurn(b2, subs, battleShips, patrols, carriers, row, col);
  19. b1.printBoard();
  20. System.out.println("b2 is ");
  21. b2.printBoard();
  22. send((Board) b2);
  23. //send((Board) b1);
  24. } // end takeTurn1
  25.  
  26. // get the move from the user and take turn for player 2
  27. // player 2 wants to take turn on player 1's board
  28. static void takeTurn2() throws IOException
  29. {
  30. String getRowCol = "Please enter a row and col 0-9 so it looks like this 1,2: ";
  31. int row = 0;
  32. int col = 0;
  33. send2((String) getRowCol);
  34. String receivedRowCol = (String) receive2();
  35. row = Integer.parseInt(getRow((String) receivedRowCol));
  36. col = Integer.parseInt(getCol((String) receivedRowCol));
  37. String rowColAre = "The row is " + row + "\nThe Col is " + col + "\n";
  38. send2((String) rowColAre);
  39. System.out.println("The row is " + row);
  40. System.out.println("The col is " + col);
  41. b1 = (Board) receive2();
  42. p2.takeTurn(b1, subs, battleShips, patrols, carriers, row, col);
  43. b2.printBoard();
  44. System.out.println("b1 is");
  45. b1.printBoard();
  46. send2((Board) b1);
  47. //send((Board) b1);
  48. } // end takeTurn1
here is where it prints it in the client and this is where i think its messing up
java Syntax (Toggle Plain Text)
  1. static void takeTurn()
  2. {
  3. try
  4. {
  5. // receiving to take turn
  6. String receive = receive();
  7. String rowCol = promptUser();
  8. send(rowCol);
  9. send(b);
  10. receive();
  11. b = ((Board) receiveObject());
  12. System.out.println();
  13. System.out.println("Board after move");
  14. b.printBoard();
  15. } // end try
  16. catch(IOException e)
  17. {
  18. System.out.println("Caught IOException in takeTurn" + e);
  19. } // end catch
  20. } // end takeTurn
I think it might flip them somewhere because when i print out b1 and b2 in the server it says b1 is b2 i think
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:36 PM   #27
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 270
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

hmmm, try sending the other board see what that outputs, is it possible for me to see a sample set of outputs?


Chris
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 3:42 PM   #28
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

Quote:
The output is:

Player 1 board displayed by client
0 w w w B w w w w w w
1 w w w B w w w w w w
2 w w w B w C w w w w
3 w w w B w C P P w w
4 w w w w w C w w w w
5 w w w w w C w w w w
6 w w w w w C w w w w
7 w w w w w w w w w w
8 w S S S w w w w w w
9 w w w w w w w w w w

Player 2 board displayed by client
0 w w w w w w w w w w
1 w w w P P w w w C w
2 w w w w w w w w C w
3 w w w w w w w w C w
4 w w B B B B w S C w
5 w w w w w w w S C w
6 w w w w w w w S w w
7 w w w w w w w w w w
8 w w w w w w w w w w
9 w w w w w w w w w w

b2 displayed by server after a move by player1
b2 is
0 x w w B w w w w w w
1 w w w B w w w w w w
2 w w w B w C w w w w
3 w w w B w C P P w w
4 w w w w w C w w w w
5 w w w w w C w w w w
6 w w w w w C w w w w
7 w w w w w w w w w w
8 w S S S w w w w w w
9 w w w w w w w w w w
Notice that it is the same as player1's board originally but it is displayed as b2
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:51 PM   #29
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

do i maybe have to flip the receives like in takeTurn1 i call receive() but store it in b2 and then in takeTurn2 i call receive2() and store it in b1 but when setting up the players i call receive() and send() in receivePlayer1() and receive2() and send2() in receivePlayer2() so its like im mixing them or something
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:56 PM   #30
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 270
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

thats because when the client sends the board to the server it sends b1 from client1, and you have the server saying it is b2 from player1

Chris
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get an email to fill out an online form? r2d246 C++ 2 Jan 16th, 2006 12:42 PM
I am back kurifu Coder's Corner Lounge 9 Oct 21st, 2005 4:31 AM
Eternity Online Lucid Project Ideas 4 May 12th, 2005 9:54 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC