HELP!!! Battleship program

Hello! Please help! We (my classmates and I) are assigned a final project to make a battleship program in which we need to win against the computer everytime! How in the world can we do that? We are basic programmers, in which we just know how to make a program that can add or subtract or whatnot but not how to make battleship. PLEASE HELP!!!

Comments

: Hello! Please help! We (my classmates and I) are assigned a final project to make a battleship program in which we need to win against the computer everytime! How in the world can we do that? We are basic programmers, in which we just know how to make a program that can add or subtract or whatnot but not how to make battleship. PLEASE HELP!!!: First you need to create 2 playing-boards: 1 for you and 1 for the computer. I would suggest a 2-D integer array:[code]var ComputerField: array[1..20, 1..20] of integer; PlayerField: array[1..20, 1..20] of integer;[/code]Then you can define your ships and water. I would suggest that you take water as a value of 1, and the ships as numbers greater than 1. If a location is hit, you can make it negative to indicate the hit. I would also make an array, in which you count the hits against each ship. This makes it easier to keep track of how many and which ships are sunk.The game plays by entering the coordinates to hit and then the computer updates the playing fields and the ship lists.The display can be an simple indicator using various characters, or could be a complete graphical appearance. The easiest way is use GotoXY() to write the characters. You might also want to use colors: TextColor() and TextBackground().If you truly want to let the player win every time, let the computer know where 1 small ship is. This way you can control where the computer fires last. The most basic game lets the computer pick the locations at random.[code] repeat x := Random(20)+1; y := Random(20)+1; until PlayerField[x, y] > 0;[/code]This however might lock the program for some time later in the game. An improvement to this, is to count the number of times the computer picked a location. After a certain number is reached search for the first positive location on the map. This way the computer won't think too long about its move.

: uh...can you help put that in lay man's terms or possibly help by showing what the whole thing is supposed to look like...we don't even know where to start or anything: I assume you are familiar with the game Battleship, and know the rules. If you don't then familiarizing yourself with that is a very good start. Here is part of the code you requested. It still needs some parts, like the human player placing his ships.[code]unit BSUtils;

procedure SetShip(var Player: TPlayerData; X, Y, Ship: integer; IsVert: boolean);var i: integer;begin with Player do begin if IsVert then for i := Y to Y+Ships[Ship].Size-1 do Field[X, I] := Ship else for i := X to X+Ships[Ship].Size-1 do Field[I, Y] := Ship; end;end;

procedure SetBoard(var Player: TPlayerData);var i, x, y: integer;begin with Player do begin for i := 1 to 4 do CreateShip(pfMineSweep, 2, Ships[i]); for i := 5 to 8 do CreateShip(pfFrigate, 3, Ships[i]); for i := 9 to 10 do CreateShip(pfCruiser, 4, Ships[i]); CreateShip(pfBattleShip, 5, Ships[11]); for x := 1 to FieldSize do for y := 1 to FieldSize do Field[x, y] := pfWater; end;end;

function IsWinner: integer;var i: integer;begin IsWinner := 1; { Assume Human has won } for i := 1 to 11 do if Computer.Ships[i].Size <> Computer.Ships[i].NumberOfHits then IsWinner := -1; { If still computer ships left, assume Computer has won } if IsWinner = 1 then Exit; for i := 1 to 11 do if Human.Ships[i].Size <> Human.Ships[i].NumberOfHits then IsWinner := 0; { If still human ships left, game not finished yet }end;

end.[/code]Any errors indicating unknown identifiers arise from the lack of a uses list. See the help files of your version of Pascal for which unit to use.

I'm really really sorry...can you maybe write the program for us? we need it this week and we are really trying to figure it out. you've helped so much but it is still very hard. i know it's asking a lot, but could you please help again. thank you so much.

: I'm really really sorry...can you maybe write the program for us? we need it this week and we are really trying to figure it out. you've helped so much but it is still very hard. i know it's asking a lot, but could you please help again. thank you so much.: I won't do your assignments for you, because then you'll never learn Pascal.

: Hello! Please help! We (my classmates and I) are assigned a final project to make a battleship program in which we need to win against the computer everytime! How in the world can we do that? We are basic programmers, in which we just know how to make a program that can add or subtract or whatnot but not how to make battleship. PLEASE HELP!!!:

Are you from Venezuela? I have a final Project too which is to make a battleship program.. :P I study at the UCV....

: : Hello! Please help! We (my classmates and I) are assigned a final project to make a battleship program in which we need to win against the computer everytime! How in the world can we do that? We are basic programmers, in which we just know how to make a program that can add or subtract or whatnot but not how to make battleship. PLEASE HELP!!!: : : : Are you from Venezuela? I have a final Project too which is to make a battleship program.. :P I study at the UCV....: : no philippines

: : : Hello! Please help! We (my classmates and I) are assigned a final project to make a battleship program in which we need to win against the computer everytime! How in the world can we do that? We are basic programmers, in which we just know how to make a program that can add or subtract or whatnot but not how to make battleship. PLEASE HELP!!!: : : : : : : Are you from Venezuela? I have a final Project too which is to make a battleship program.. :P I study at the UCV....: : : : : no philippines:

If you find the program I will appreciate that you posted it here please!!! And if i find it i will do the same...