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:57 PM   #31
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

o ok, so im just confusing myself basically? I flipped the sends and receives around so they are opposite the takeTurn method so takeTurn1 uses send2() and receive2() and that seems to take the right boards but it still executes the move on the wrong player's board.
cwl157 is offline   Reply With Quote
Old May 15th, 2008, 3:59 PM   #32
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: back to online battleship

it would indeed appear that way lol just take a 5 min break get a coffee, then read through your code slowley and it will be clearer to you and you will notice the little out of place things

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 4:13 PM   #33
iEngage
Newbie
 
iEngage's Avatar
 
Join Date: May 2008
Location: teh interwebz
Posts: 22
Rep Power: 0 iEngage is on a distinguished road
Re: back to online battleship

ah yes the coffee break. I am emphasizing the importance of taking a break.

I would even take a longer break. maybe watch a TV show or play a video game for half an hour.

When you come back to your code, approach the problem as if you weren't the author of the code. just work through it slowly and try to pinpoint exactly where in the code the problem occurs and go from there.

works every time.. hehe
__________________
iEngage
iEngage is offline   Reply With Quote
Old May 16th, 2008, 8:45 AM   #34
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

alright i have no idea i think ive tried every possible combo of sending and receiving of different boards to the 2 players and can not get it to where player 1 moves on the other board. They always move on their own board
cwl157 is offline   Reply With Quote
Old May 17th, 2008, 3:47 PM   #35
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Re: back to online battleship

For what its worth, I think that sending the board back and forth is a bad idea.

To approach this problem you should have classes that represent the board for each player. Then, you should have an additional class that represents an "Action request". This class would be able to interact with the two players, accepting a "strike attempt" and replying with either a hit or a miss, and requesting that each players "board" class update their board in response to this information. If you do not have this additional class, it will make the problem harder to solve. With this class, you can simply send an object of the class back and forth a couple times per turn and have each player update their board appropriately. You should not be using Client and Server to play the game. You should be using appropriate classes to represent the board. Then Player1 will take a turn, which will just update an Action Request object. Player2 will have a method, lets call it "evalAction". When Player2 receives the Action Request object, it will call Action Request object.evalAction(). evalAction should be implemented so that it will update the game board based on whatever is in the Action Request object. Then evalAction will update the Action request object again, and send it back to player 1. Lets look at a possibility of how this would work:

1) Player 1 enters information indicating he wants to hit a square, lets call is sq8
2) The Action Request object is updated, via a method (doesn't matter what it is), which will make the Action Request object basically say that Player1 is trying to hit sq8.
3)Player 2's evalAction method checks the Action Request object, and looks at varying information on its own board, such as was it a hit or a miss? Then Player2 calls its own method to update it's board, then calls a method to guess its own square.
4) This process can just be repeated on each Player.



Also, I just saw that you were using ObjectOutputStream. You should note: I think ObjectOutputStream requires any objects sent over it to implement the class 'Serialized'. If you are sending over objects that do not implement the Serialized interface, this could be causing you problems.

Last edited by Fall Back Son; May 17th, 2008 at 4:02 PM.
Fall Back Son is offline   Reply With Quote
Old May 17th, 2008, 7:16 PM   #36
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 255
Rep Power: 1 Jabo is on a distinguished road
Re: back to online battleship

why not just send 2 arrays, one with ship coordinates, and one with called shots coordinates to both players every turn to ensure they have the correct board setup. The player then sends a new shot to the server, the server adds it to the shots array and compares it to the ship coordinates array, then sends the results to the both players and a call hit or miss to the firing player. This keeps everything on the server, and players only get updates.

Of course what I posted is watered down, as you don't want to send all ship coordinates to both players, and you don't want to send all shots to both players. The client software is only responsible for taking the arrays and setting up the board, and prompting the player for a shot; no sending of the whole board, just the coordinates.

Last edited by Jabo; May 17th, 2008 at 7:31 PM.
Jabo is offline   Reply With Quote
Old May 17th, 2008, 8:54 PM   #37
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Re: back to online battleship

Because the correct OOP way to do it is what I described above. Also, because you can just send one object which can contain the information you want (however you want to store it, be it an array, whatever) which can provide useful methods for dealing with that information.
Fall Back Son is offline   Reply With Quote
Old May 17th, 2008, 11:50 PM   #38
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 255
Rep Power: 1 Jabo is on a distinguished road
Re: back to online battleship

oic, I must have overlooked where he said it must be OOP oriented.

anywho, if this is something for fun, that's ok, but if it's ever intended to be put into serious use, the peer->peer model will be prone to hacking/cracking; even more so than a server->client model
Jabo is offline   Reply With Quote
Old May 18th, 2008, 3:23 PM   #39
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Re: back to online battleship

Quote:
Originally Posted by Jabo View Post
oic, I must have overlooked where he said it must be OOP oriented.

anywho, if this is something for fun, that's ok, but if it's ever intended to be put into serious use, the peer->peer model will be prone to hacking/cracking; even more so than a server->client model
I only responded due to where you said, "why not just..." which made it sound like your solution was easier, when in fact, its more difficult and confusing. And this has to do with OOP since the problem can most easily be implemented using OO techniques. And I also suggested my method because it makes it easier to locate errors in the code, and it makes it easier to write the code you need. I'm not knocking your method, I just think its getting away from the reason he's having trouble in the first place. He's having trouble because he didn't break the problem down in the first place and think it through all the way. Thats why he can't locate errors, among other logic problems. Which is fine... and I've done the same thing. Thats why I wrote out what I did.

The end.
Fall Back Son is offline   Reply With Quote
Old May 18th, 2008, 4:42 PM   #40
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
Re: back to online battleship

fall back son,
Your method does make sense and i will try to do this. I think part of the problem is i originally made it so the computer just used random numbers to simulate battleship and then tried to adapt it to play over a network thinking that the logic of the game is the same but it looks like i can't just force that and need to redesign it so the actions are handled better. I do have some questions though like that action request object how is that updated, and how does player 2 know about it and how does the server fit into it all? Like i have said i have never done any network programming ever so i guess im lost on the overall flow of the program?

Last edited by cwl157; May 18th, 2008 at 4:52 PM.
cwl157 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 11:16 AM.

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