Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: naval battle game problem help  (Read 12006 times)

0 Members and 1 Guest are viewing this topic.

orux

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    naval battle game problem help
    « on: October 20, 2013, 08:26:24 AM »
    Hey there, my first post here.

    I'm making a little naval battle game for uni (u know, that two coordinates based game). txt files contains coordinates of firstplayers "pirmaszaidejas.txt", secondplayer "antraszaidejas",  coordinates are like this: one line for one coordinate (letter and number), and empty line between ships. I need to change background color when someone hits and to delete guessed line and write it to another file.

    Now it says neteisingos kordinates which means  wrong coordinates even tho I'm picking right coords. Also it doesn't change between players.

    P.S. At first I want to check whether there are such coordinates and if there are to continue. (t stands for yeas, and n stands for no).

    I'm adding all necessary files (I hope). If you have any questions in order to help me please ask I'll try to explain.

    [recovering disk space, attachment deleted by admin]

    Salmon Trout

    • Guest
    Re: naval battle game problem help
    « Reply #1 on: October 20, 2013, 12:50:20 PM »
    You need to study syntax some more, especially FOR...

    One example: at line 81 (This is all one line! 661 chars!) (I have split it to make this post possible!)

    for %%U in (R1,E1,S1,P1,U1,B1,L1,I1,K1,A1,R2,E2,S2,P2,U2,B2,L2,I2,K2,A2,R3,E3,S3,
    P3,U3,B3,L3,I3,K3,A3,R4,E4,S4,P4,U4,B4,L4,I4,K4,A4,R5,E5,S5,P5,U5,B5,L5,I5,K5,A5,
    R6,E6,S6,P6,U6,B6,L6,I6,K6,A6,R7,E7,S7,P7,U7,B7,L7,I7,K7,A7,R8,E8,S8,P8,U8,B8,L8,
    I8,K8,A8,R9,E9,S9,P9,U9,B9,I9,K9,A9,R10,E10,S10,P10,U10,B10,L10,I10,K10,A10)
    do findstr /C:"R1 E1 S1 P1 U1 B1 L1 I1 K1 A1 R2 E2 S2 P2 U2 B2 L2 I2 K2 A2 R3 E3
    S3 P3 U3 B3 L3 I3 K3 A3 R4 E4 S4 P4 U4 B4 L4 I4 K4 A4 R5 E5 S5 P5 U5 B5 L5 I5 K5
    A5 R6 E6 S6 P6 U6 B6 L6 I6 K6 A6 R7 E7 S7 P7 U7 B7 L7 I7 K7 A7 R8 E8 S8 P8 U8 B8
    L8 I8 K8 A8 R9 E9 S9 P9 U9 B9 I9 K9 A9 R10 E10 S10 P10 U10 B10 L10 I10 K10 A10" AntrasZaidejas.txt

    That is a one-line FOR command. You are now outside the loop and %%U is no longer a loop variable (it is the literal string "%%U")
    Execution will probably (!) never go to hit1


    if %%U == %a%%b% goto hit1
    goto missed1
    « Last Edit: October 20, 2013, 01:48:10 PM by Salmon Trout »

    orux

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows 7
      Re: naval battle game problem help
      « Reply #2 on: October 21, 2013, 06:56:56 AM »
      Thanks for the answer. This is probably my biggest problem... How to check all these coordinates?? I was thinking about using for + findstr, but I'm not really sure...

      kyle_engineer



        Intermediate
      • 010010110101100
      • Thanked: 4
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: naval battle game problem help
      « Reply #3 on: October 21, 2013, 09:48:00 PM »
      Personally, I think I would store the coordinates in variables, rather than .txt files. I think it would be easier to argue the coordinates that way. Also if you wanted to 'save' the coordinates, you could just dump them to a .txt file which will be loaded next time.

      From what I can tell, you're basically trying to make something like Battle Ship, but for DOS. If that's the case, I'm sure you couuld find some snippets to help you.
      "Any answer is only as good as it satisfies the question." - Me

      0000000100101011000 -
      010010010010000001001100010011110100110 001000000010110010100111101010101

      orux

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows 7
        Re: naval battle game problem help
        « Reply #4 on: October 22, 2013, 01:21:11 AM »
        Yep that's probably battle ship. How should I store coordinates in variables?

        orux

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Windows 7
          Re: naval battle game problem help
          « Reply #5 on: October 22, 2013, 03:01:02 AM »
          Do you mean that I should do something like this (see attachment)? lets say I'm doing like that. still how should i check whether players typed correct coords or not  ( for example if we have a grid with word respublika (10 letters) and numbers from 1 to 10).
          I mean if they typed something like "m15" instead of lets say "r9" you got the idea. I assume I should use for command. something like: for %%U in (all those coordinates) if %%U == %all those sets from attachment%.

          Or I'm thinking in a wrong way at all? because it may be the case :)

          [recovering disk space, attachment deleted by admin]

          orux

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Windows 7
            Re: naval battle game problem help
            « Reply #6 on: October 22, 2013, 10:41:34 AM »
            Here's a bit of an update. I'm making it simpler because my deadline is coming... Now each of ships takes just one coordinate. And when player picks coordinates, as far as I'm understanding it should go through all possible variations (r1-r10,a1-a10) and see if given coordinate matches previous player coordinates. (pirm zaid stands for first player and antrzaid stands for secondplayer).
            @echo off
            echo laivu musis.
            echo 2 zaidejai.
            echo Ar norite pradeti?
            echo jei taip spauskite, bet kuri klavisa, jei ne ctrl+c.
            pause>null

            TITLE NAVAL BATTLE

            echo pasirinkite:
            echo T - Pradeti zaidima
            echo N - Baigti zaidima

            CHOICE/c:TN
            if errorlevel 255 goto end
            if errorlevel 2 goto end
            goto start

            :start
            echo.
            goto firstplayer
            goto secondplayer

            :firstplayer
            echo pirmas zaidejas iveda savo 10 laivu. 1 koordinate = 1 laivas
            set /p x1=
            set /p x2=
            set /p x3=
            set /p x4=
            set /p x5=
            set /p x6=
            set /p x7=
            set /p x8=
            set /p x9=
            set /p x10=

            :continuegame
            echo pasirinkite ar testi?
            choice/c:TN
            if errorlevel 255 goto end
            if errorlevel 2 goto end
            goto clean

            :clean
            cls
            goto secondplayer

            :secondplayer
            echo antras zaidejas iveda savo 10 laivu. 1 koordinate = 1 laivas
            set /p y1=
            set /p y2=
            set /p y3=
            set /p y4=
            set /p y5=
            set /p y6=
            set /p y7=
            set /p y8=
            set /p y9=
            set /p y10=

            :continuegame
            echo pasirinkite ar testi?
            choice/c:TN
            if errorlevel 255 goto end
            if errorlevel 2 goto end
            goto cls

            :cls
            cls
            goto PirmZaid

            :PirmZaid
            echo Pirmo zaidejo eile.
            echo pasirinkite koordinates. Pirma raide ir tada skaiciu.
            set /p a=

            for %%U in (R1,E1,S1,P1,U1,B1,L1,I1,K1,A1,R2,E2,S2,P2,U2,B2,L2,I2,K2,A2,R3,E3,S3,
            P3,U3,B3,L3,I3,K3,A3,R4,E4,S4,P4,U4,B4,L4,I4,K4,A4,R5,E5,S5,P5,U5,B5,L5,I5,K5,A5,
            R6,E6,S6,P6,U6,B6,L6,I6,K6,A6,R7,E7,S7,P7,U7,B7,L7,I7,K7,A7,R8,E8,S8,P8,U8,B8,L8,
            I8,K8,A8,R9,E9,S9,P9,U9,B9,I9,K9,A9,R10,E10,S10,P10,U10,B10,L10,I10,K10,A10) do if %a% == %y1%%y2%%y3%%y4%%y5%%y6%%y7%%8%%y9%%y10% goto hit1
            goto AntrZaid

            :hit1
            goto setcolor1
            :setcolor1
            color 4f
            goto shootagain1

            :shootagain1
            color 0f
            goto PirmZaid

            :AntrZaid
            echo Antro zaidejo eile.
            echo pasirinkite koordinates. Pirma raide ir tada skaiciu.
            set /p a=

            for %%U in (R1,E1,S1,P1,U1,B1,L1,I1,K1,A1,R2,E2,S2,P2,U2,B2,L2,I2,K2,A2,R3,E3,S3,
            P3,U3,B3,L3,I3,K3,A3,R4,E4,S4,P4,U4,B4,L4,I4,K4,A4,R5,E5,S5,P5,U5,B5,L5,I5,K5,A5,
            R6,E6,S6,P6,U6,B6,L6,I6,K6,A6,R7,E7,S7,P7,U7,B7,L7,I7,K7,A7,R8,E8,S8,P8,U8,B8,L8,
            I8,K8,A8,R9,E9,S9,P9,U9,B9,I9,K9,A9,R10,E10,S10,P10,U10,B10,L10,I10,K10,A10) do if %a% == %x1%%x2%%x3%%x4%%x5%%x6%%x7%%x8%%x9%%x10% goto hit2
            goto PirmZaid

            :hit2
            goto setcolor2
            :setcolor2
            color 4f
            goto shootagain2

            :shootagain2
            color 0f
            goto AntrZaid
             
            :end


            now doesn't matter what I'm inputing, I'm only changing from first player to second player forever. Help is more than welcome.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: naval battle game problem help
            « Reply #7 on: October 22, 2013, 11:16:48 AM »
            It's difficult to see what is being done, and what you expect.


            orux

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows 7
              Re: naval battle game problem help
              « Reply #8 on: October 22, 2013, 11:30:51 AM »
              well, How I'm imagining it :) : At first player chooses wether to continue or not. If yes (or T) players need to write coordinates. firstplayer starts by entering coordinates of 10 ships (for example one ship L5, because they're playing on a grid). Then program asks do players want to continue? if so screen is being cleaned and second player puts its' fleet coordinates. Then again program asks shall it continue? if so, screen is being cleaned lastly and it's firstplayer move. He should choose random coordinate from grid (will show grid at the end of post) and if that random coordinate matches any of the second players' ship, it should set background color to red and let the first player shoot again. If it doesn't match, then go to the secondplayer turn immediately.

              Grid:
                RESPUBLIKA
              1
              2
              3
              4
              5
              6
              7
              8
              9
              10

              Basically 10 on 10 grid.
              Hope it helps.

              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: naval battle game problem help
              « Reply #9 on: October 22, 2013, 11:48:05 AM »
              One issue you will have is that you can't change the background colour of just one position on the screen, without using either a third party utility or some convoluted scripting and formatting of your screen output.

              orux

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Windows 7
                Re: naval battle game problem help
                « Reply #10 on: October 22, 2013, 11:57:43 AM »
                so, the best option would be to change both background and foreground then?  could you tell something about my main problem? When I'm reaching part of program where first player picks random coordinate. At this point it allows me to write anything (while it should be only combination of letter and number from grid) moreover when I'm hitting enter after typing (no matter what) program gives second player turns. As I said it seems like program ignores that "random coord" I can type something like "mm" and it moves to second player. even if I'm typing proper coordinates (that should hit the target) it still moves.

                What coordinates I'v chosen for testing:
                1stplayer (or  set /p xn=):           2ndplayer(or set/p yn=):
                R1                                                 R1     
                B2                                                 P2
                A4                                                 L3
                P5                                                 A4
                L5                                                 R5
                R6                                                 U5
                K7                                                 B7
                B8                                                 E9
                R10                                               K9
                K10                                              L10

                Lemonilla



                  Apprentice

                • "Too sweet"
                • Thanked: 70
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: naval battle game problem help
                « Reply #11 on: October 22, 2013, 01:37:37 PM »
                One issue you will have is that you can't change the background colour of just one position on the screen, without using either a third party utility or some convoluted scripting and formatting of your screen output.

                I don't know if this is considered a "convoluded scripting" but here is a way that works on windows 7

                Code: [Select]
                :: Jeb Stack Overflow.com
                :: http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-batch-file/5344911#5344911

                @echo off
                SETLOCAL EnableDelayedExpansion
                for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
                  set "DEL=%%a"
                )

                echo say the name of the colors, don't read

                call :ColorText 0a "blue"
                call :ColorText 0C "green"
                call :ColorText 0b "red"
                echo.
                call :ColorText 19 "yellow"
                call :ColorText 2F "black"
                call :ColorText 4e "white"
                echo.
                pause
                goto :Year

                goto :eof

                :ColorText
                echo off
                <nul set /p ".=%DEL%" > "%~2"
                findstr /v /a:%1 /R "^$" "%~2" nul
                del "%~2" > nul 2>&1
                goto :eof













                :Year



                @echo off
                setlocal EnableDelayedExpansion
                for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
                  set "DEL=%%a"
                )

                rem Prepare a file "X" with only one dot
                <nul > X set /p ".=."

                call :color 1a "a"
                call :color 1b "b"
                call :color 1c "^!<>&| %%%%"*?"
                pause
                exit /b

                :color
                set "param=^%~2" !
                set "param=!param:"=\"!"
                findstr /p /A:%1 "." "!param!\..\X" nul
                <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
                exit /b

                To do this you would need a loop and loop through the collums until you get to the end of the line, which 'echo.' would end.

                Quote from: patio
                God Bless the DOS Helpers...
                Quote
                If it compiles, send the files.

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: naval battle game problem help
                « Reply #12 on: October 22, 2013, 02:03:25 PM »
                so, the best option would be to change both background and foreground then?

                Basic batch commands change the entire screen colour, not just one character.

                first player picks random coordinate. At this point it allows me to write anything (while it should be only combination of letter and number from grid)

                You will have to parse each input string and check firstly that it is either 2 or 3 characters, and then that the first character is a lower/upper case letter and the second 1 or 2 character is a digit, and ask for further input if it is not.

                Checking it is possible with a regular expression, but findstr has bugs when checking character classes.
                The alternative is to do it manually with plain batch code, or use VBS to check the characters.



                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: naval battle game problem help
                « Reply #13 on: October 22, 2013, 02:07:54 PM »
                I don't know if this is considered a "convoluded scripting" but here is a way that works on windows 7

                There's no 'd' in convoluted. :D   

                That method doesn't handle the full spectrum of characters, but here is a script that works for more characters:

                Code: [Select]
                @Echo Off
                Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
                Pause >Nul
                Exit /B

                :Color
                :: v21
                :: Arguments: hexColor text [\n] ...
                :: \n -> newline ... -> repeat
                :: Supported in windows XP, 7, 8.
                :: In XP extended ascii characters are printed as dots.
                :: For print quotes, use empty text.
                SetLocal EnableExtensions EnableDelayedExpansion
                Subst `: "!Temp!" >Nul &`: &Cd \
                SetLocal DisableDelayedExpansion
                If Not Exist `.7 (
                Echo(|(Pause >Nul &Findstr "^" >`)
                Set /P "=." >>` <Nul
                For /F "delims=;" %%# In (
                '"Prompt $H;&For %%_ In (_) Do Rem"') Do (
                Set /P "=%%#%%#%%#" <Nul >`.3
                Set /P "=%%#%%#%%#%%#%%#" <Nul >`.5
                Set /P "=%%#%%#%%#%%#%%#%%#%%#" <Nul >`.7))
                :__Color
                Set "Text=%~2"
                If Not Defined Text (Set Text=^")
                SetLocal EnableDelayedExpansion
                Set /P "LF=" <` &Set "LF=!LF:~0,1!"
                For %%# in ("!LF!") Do For %%_ In (
                \ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
                For /F delims^=^ eol^= %%# in ("!Text!") Do (
                If #==#! EndLocal
                If \==%%# (Findstr /A:%~1 . \` Nul
                Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
                Type `.5) Else (Echo %%#\..\`>`.dat
                Findstr /F:`.dat /A:%~1 .
                Type `.7))
                If "\n"=="%~3" (Shift
                Echo()
                Shift
                Shift
                If ""=="%~1" Goto :Eof
                Goto :__Color

                orux

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: naval battle game problem help
                  « Reply #14 on: October 22, 2013, 02:39:23 PM »
                  thanks for answers. I've been working on code by myself a bit. before seeing your answers.. I'm now trying to put coordinates in variables as someone suggested. without findstr at all. also haven't fixed the color issue yet. Trying to get main stuff working at first. will take a look at this tomorrow. It's too late here on my side of the world.

                  [recovering disk space, attachment deleted by admin]

                  patio

                  • Moderator


                  • Genius
                  • Maud' Dib
                  • Thanked: 1769
                    • Yes
                  • Experience: Beginner
                  • OS: Windows 7
                  Re: naval battle game problem help
                  « Reply #15 on: October 22, 2013, 03:15:57 PM »
                  Quote
                  There's no 'd' in convoluted. :D   

                  Check again...
                  " Anyone who goes to a psychiatrist should have his head examined. "

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: naval battle game problem help
                  « Reply #16 on: October 22, 2013, 03:23:26 PM »

                  patio

                  • Moderator


                  • Genius
                  • Maud' Dib
                  • Thanked: 1769
                    • Yes
                  • Experience: Beginner
                  • OS: Windows 7
                  Re: naval battle game problem help
                  « Reply #17 on: October 22, 2013, 07:08:18 PM »
                  Foxi you do great work in this section but i couldn't resist...
                  " Anyone who goes to a psychiatrist should have his head examined. "

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: naval battle game problem help
                  « Reply #18 on: October 22, 2013, 09:08:04 PM »
                  Thanks, it serves me right for being a little bit 'smart'. :)  All in good fun.

                  kyle_engineer



                    Intermediate
                  • 010010110101100
                  • Thanked: 4
                    • Yes
                  • Certifications: List
                  • Computer: Specs
                  • Experience: Expert
                  • OS: Windows 7
                  Re: naval battle game problem help
                  « Reply #19 on: October 23, 2013, 02:23:49 PM »
                  I'm now trying to put coordinates in variables as someone suggested.

                  That was me. :P

                  I was working on a really nice verbose reply, then my blackberry browser crashed and I lost it all... so no more of that. lol!

                  There are a couple more suggestions I have too...

                  1) I'd recommend using row numbers 0-9 rather than 1-10. Just personally I think it would be easier to work with and  wouldn't run the risk of a 3rd character ever being an issue.

                  2) In the normal game Battleship, you can align your ships either vertically (along columns only) or horizontally (along rows only). But you can have some ships one way, and some the other. For simplicity's sake I'd recommend writing your script to only use one of the alignments. This way you don't have to worry so much about ships overlaying each others' coordinates. Although, you will still have that as a problem, it is not as much of an issue only using this method. Plus it makes it easier to write the computer "player's" logic if you're doing that.

                  3) I don't remember if you can put wildcards into a FOR loop in this way or not (TBH I have kind of avoided FOR for a while cause I didn't really understand it until recently), but I was thinking something like this to check your coordinates (once they are bound to a variable):

                  Code: [Select]
                  FOR %%a IN (A*, B*, C*, D*, E*, F*, G*, H*, I*, J*) DO (IF '%%a'=='%shot%' goto %hit%
                  I think that get's the concept across. However, that only works nicely if A) you can use a wildcard there, and B) if your variables are kept to 3 characters (as a third could cause problems later if not here).

                  If that didn't work, you could make several small sections like this:

                  Code: [Select]
                  :A_checker
                  REM check column A
                  set /a row=0
                  :checker_sub
                  set coord=A%row%
                  if '%coord%'=='%shot%' goto HIT
                  set /a row=%row%+1
                  if '%row%'=='10' goto B_checker
                  goto checker_sub

                  anyway, just some ideas.

                  Again though, I haven't taken the time to try any of this - so I'll assume if you do try it that you adopt proper syntax. ;)
                  "Any answer is only as good as it satisfies the question." - Me

                  0000000100101011000 -
                  010010010010000001001100010011110100110 001000000010110010100111101010101

                  orux

                    Topic Starter


                    Rookie

                    • Experience: Beginner
                    • OS: Windows 7
                    Re: naval battle game problem help
                    « Reply #20 on: October 30, 2013, 03:35:18 PM »
                    I think I'm a ok with checking (just used multiple ifs), yet now my lecturer says that there's an error with set command... I Really can't find it. Help would be more than welcome.

                    [recovering disk space, attachment deleted by admin]

                    Lemonilla



                      Apprentice

                    • "Too sweet"
                    • Thanked: 70
                    • Computer: Specs
                    • Experience: Experienced
                    • OS: Windows 7
                    Re: naval battle game problem help
                    « Reply #21 on: October 30, 2013, 08:12:44 PM »
                    well check1 10 will always return false if im not mistaken, and you are using the wrong / on your set /p.
                     
                    You seem to have a lot of repeating code, try using setlocal enabledelayedexpansion to cut it down a bit. 
                    you can do stuff like set /p x!a!=  and echo !%x%_%y%! which is how i`ve been storing my coordinates (forgive me for stealing your project idea)
                    Quote from: patio
                    God Bless the DOS Helpers...
                    Quote
                    If it compiles, send the files.

                    orux

                      Topic Starter


                      Rookie

                      • Experience: Beginner
                      • OS: Windows 7
                      Re: naval battle game problem help
                      « Reply #22 on: November 01, 2013, 01:29:22 PM »
                      No worries I forgive you ;). I've changed that slash because I thought it was error. Obviously not... I think i do not need to use echo because I don't need to see those coordinates. Yet could you explain why check1 10 would be false? As far as I understand it should be true if it wouldn't be equal to any of previous coordinates. I've used this system to all checks. So maybe that's the reason why I can type more coordinates than needed and those can be the same (A1 A1 A1 more than 10 times). And There still should be that set error somewhere hidden :/.

                      P.S. you may check code just until continuegame command, rest part is either almost the same or just blockout of code.

                      orux

                        Topic Starter


                        Rookie

                        • Experience: Beginner
                        • OS: Windows 7
                        Re: naval battle game problem help
                        « Reply #23 on: November 01, 2013, 01:48:26 PM »
                        attachment

                        [recovering disk space, attachment deleted by admin]

                        Lemonilla



                          Apprentice

                        • "Too sweet"
                        • Thanked: 70
                        • Computer: Specs
                        • Experience: Experienced
                        • OS: Windows 7
                        Re: naval battle game problem help
                        « Reply #24 on: November 01, 2013, 03:01:29 PM »
                        No worries I forgive you ;). I've changed that slash because I thought it was error. Obviously not... I think i do not need to use echo because I don't need to see those coordinates. Yet could you explain why check1 10 would be false? As far as I understand it should be true if it wouldn't be equal to any of previous coordinates. I've used this system to all checks. So maybe that's the reason why I can type more coordinates than needed and those can be the same (A1 A1 A1 more than 10 times). And There still should be that set error somewhere hidden :/.

                        P.S. you may check code just until continuegame command, rest part is either almost the same or just blockout of code.

                        I apologize about the check1_10 bit, I was using my tablet which wasn't showing the "!", so it looked like "if x5==x6" which is always wrong.

                        When I run it, it doesn't seem to do much of anything.  Am I missing a component file?  I might be missing something, as I can't read the instructions though.  I'll highlight some of things that stand out to me anyway.


                        Code: [Select]
                        :check1_10
                        set /p x!10!=
                        You don't have setlocal EnableDelayedExpansion, so this will always save the veriable as "x!10!" and not x<value of 10>.
                        Code: [Select]

                        T:\>set /p x!1!=
                        2

                        T:\>set x
                        x!1!=2

                        EDIT: I think I've figured it out (maybe) but I keep getting stuck at "set /p x!8!=" or check1_8

                        EDIT2: I don't know if this helps you, but here is what I have so far. Maybe you can use some of the ideas/processes to your benefit.
                        Code: [Select]
                        :: This is designed for windows 7 and is not guaranteed to work on any other OS. ::

                        @echo off
                        title Naval Game
                        color 07
                        setlocal EnableDelayedExpansion
                        for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
                          set "DEL=%%a"
                        )
                        <nul > X set /p ".=."
                        :start

                        call :Newgame
                        call :displayBoard
                        call :move
                        :main
                        call :CheckWin
                        call :displayBoard
                        call :move

                        goto :main

                        :CheckWin
                        set ok=0
                        set ok.total=0
                        set y=1
                        :checkwin.loop1
                        set x=1
                        :checkwin.loop2
                        if "!%x%_%y%!"=="X" set /a ok+=1
                        if "!B%x%_%y%!"=="X," set /a ok.total+=1
                        set /a x+=1
                        if %x% LSS 9 goto :checkwin.loop2
                        set /a y+=1
                        if %y% LSS 9 goto :checkwin.loop1

                        if not %ok% EQU %ok.total% goto :eof

                        cls
                        echo You Won in %turn% turns!
                        pause>nul
                        exit

                        :move
                        echo.
                        set move=
                        set /p move=^>
                        if not defined move goto :move
                        set /a turn+=1

                        if /i "%move%"=="set" set && pause >nul
                        if /i "%move%"=="reset" goto :start


                        if /i "%move:~0,1%"=="A" set "x=1" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="B" set "x=2" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="C" set "x=3" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="D" set "x=4" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="E" set "x=5" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="F" set "x=6" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="G" set "x=7" && set y=%move:~1,1%
                        if /i "%move:~0,1%"=="H" set "x=8" && set y=%move:~1,1%

                        if /i "%move:~1,1%"=="A" set "x=1" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="B" set "x=2" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="C" set "x=3" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="D" set "x=4" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="E" set "x=5" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="F" set "x=6" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="G" set "x=7" && set y=%move:~0,1%
                        if /i "%move:~1,1%"=="H" set "x=8" && set y=%move:~0,1%

                        set cord=%x%_%y%

                        REM CHECK CORD
                        if "!B%cord%!"=="X," set %cord%=X
                        if "!B%cord%!"=="0," set %cord%=M

                        goto :eof


                        :NewGame
                        cls
                        echo Loading, Please Wait . . .
                        set turn=1
                        for /l %%X in (1,1,8) do (
                        for /l %%Y in (1,1,8) do (
                        set %%X_%%Y=0
                        set "B%%X_%%Y=0,"
                        )
                        )

                        REM Create Board
                        set ship_Num=0
                        :creatShip
                        set /a Ship_Num+=1
                        set /a ran_x=%random%*8/32768+1
                        set /a ran_y=%random%*8/32768+1
                        set /a ran_dir=%random%*4/32768+1
                        set /a ran_l=%random%*4/32768+2

                        set "B%ran_x%_%ran_y%=X,"

                        set working_x=%ran_x%
                        set working_y=%ran_y%

                        :CreatePoints
                        if "%ran_dir%"=="1" set /a working_X=%working_X%+1
                        if "%ran_dir%"=="2" set /a working_X=%working_X%-1
                        if "%ran_dir%"=="3" set /a working_Y=%working_Y%+1
                        if "%ran_dir%"=="4" set /a working_Y=%working_Y%-1
                        if %working_X% GTR 8 goto :NewGame
                        if %working_X% LSS 0 goto :NewGame
                        if %working_Y% GTR 8 goto :NewGame
                        if %working_Y% LSS 0 goto :NewGame
                        if "!B%working_X%_%working_Y%!"=="X," goto :NewGame
                        set "B%working_x%_%working_y%=X,"
                        set /a ran_l-=1
                        if not %ran_l% EQU -1 goto :createPoints

                        if %Ship_num% LSS 3 set ship_num-=1 && goto :creatShip

                        REM Record Map
                        if exist game.txt del game.txt
                        set y=1
                        :loop_y
                        set x=1
                        :loop_x
                        set line=%line%!B%x%_%y%!
                        set /a x+=1
                        if %x% LSS 9 goto :loop_x
                        echo %line% >>game.txt
                        set line=
                        set /a y+=1
                        if %y% LSS 9 goto :loop_y

                        goto :eof

                        :displayBoard
                        cls
                        if "%turn:~1,1%"=="" echo.%turn%  A B C D E F G H
                        if not "%turn:~1,1%"=="" echo.%turn% A B C D E F G H
                        set y=1
                        :loop1
                        0>nul set /p"=%y%  "
                        set x=1
                        :loop2
                        if "!%x%_%y%!"=="0" call :color 09 "0 "
                        if "!%x%_%y%!"=="X" call :color 0c "X "
                        if "!%x%_%y%!"=="M" call :color 0e "0 "
                        0>nul set /p"= "
                        set /a x+=1
                        if %x% LSS 9 goto :loop2
                        echo.
                        set /a y+=1
                        if %y% LSS 9 goto :loop1
                        goto :eof

                        :color
                        set "param=^%~2" !
                        set "param=!param:"=\"!"
                        findstr /p /A:%1 "." "!param!\..\X" nul
                        <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
                        exit /b
                        « Last Edit: November 01, 2013, 03:44:18 PM by Lemonilla »
                        Quote from: patio
                        God Bless the DOS Helpers...
                        Quote
                        If it compiles, send the files.

                        orux

                          Topic Starter


                          Rookie

                          • Experience: Beginner
                          • OS: Windows 7
                          Re: naval battle game problem help
                          « Reply #25 on: November 02, 2013, 02:10:27 AM »
                          well, yesterday night I worked a bit myself on this. Now everything seems working except that I can still type after entering 10th coordinates. Btw I was missing percentage sign in my ifs' so that was probably that set mistake. Thanks for showing your code. Problem is, i'm not yet familiar with EnableDelayedExpansion command so I'll need to check it out.

                          [recovering disk space, attachment deleted by admin]

                          orux

                            Topic Starter


                            Rookie

                            • Experience: Beginner
                            • OS: Windows 7
                            Re: naval battle game problem help
                            « Reply #26 on: November 02, 2013, 02:35:08 PM »
                            Yep seems I'm stuck with check1_8 as well. So I guess check1_8 check1_9 check1_10 will provide errors as well... wonder why tho... system is the same.

                            orux

                              Topic Starter


                              Rookie

                              • Experience: Beginner
                              • OS: Windows 7
                              Re: naval battle game problem help
                              « Reply #27 on: November 02, 2013, 03:53:46 PM »
                              I've figured out the problem with chek1_8 i think. Some of my commands were misspelled. Now coordinates works for both players. Next Step: fix the hitting. Cya.

                              [recovering disk space, attachment deleted by admin]

                              orux

                                Topic Starter


                                Rookie

                                • Experience: Beginner
                                • OS: Windows 7
                                Re: naval battle game problem help
                                « Reply #28 on: November 03, 2013, 03:37:50 AM »
                                Now, this version kinda works. Yet it still needs last thing: To check if there are any more ships left and if there aren't to announce winner. The rest will be only details (like instructions (that i need to add), color of background if I figure how to; that i wouldn't need to retype all coordinates if one is wrong, etc)

                                [recovering disk space, attachment deleted by admin]

                                foxidrive



                                  Specialist
                                • Thanked: 268
                                • Experience: Experienced
                                • OS: Windows 8
                                Re: naval battle game problem help
                                « Reply #29 on: November 03, 2013, 05:16:26 AM »
                                Just a comment here - if you make a script with English inside it, then maybe people will be more inclined to offer help.

                                It takes a fair amount of effort to analyse a large script when it works properly, and more effort again to analyse a script that is broken, or incomplete.
                                If it is in a foreign language then it takes even more work.



                                orux

                                  Topic Starter


                                  Rookie

                                  • Experience: Beginner
                                  • OS: Windows 7
                                  Re: naval battle game problem help
                                  « Reply #30 on: November 03, 2013, 06:02:27 AM »
                                  I do understand you, problem is, I'm not sure if I can use English in my code (you know, I'm not exchange student or anything, so why should I use it). Anyway, for now more than half of code commands is in English.
                                  Translation of rest:

                                  @echo off
                                  echo laivu musis.
                                  echo 2 zaidejai.
                                  echo Ar norite pradeti?
                                  echo jei taip spauskite, bet kuri klavisa, jei ne ctrl+c.
                                  pause>null
                                  // 2nd line: naval battle
                                  // 2 players
                                  // do you wabt to start?
                                  // if so press anything, if not ctrl+c //these are kinda default

                                  echo pasirinkite:
                                  echo T - Pradeti zaidima
                                  echo N - Baigti zaidima

                                  CHOICE/c:TN

                                  //echo pasirinkite == choice:
                                  //T == start game
                                  //N == end game

                                  echo pirmas zaidejas iveda savo 10 laivu. 1 koordinate = 1 laivas
                                  //first player enters his fleet of 10 ships 1coordinate equals 1 ship

                                  prn1 like message1 or msg1

                                  :prn1
                                  echo tokiu koordinaciu but negali, iveskite is naujo.
                                  goto firstplayer

                                  //echo such coordinates does not exist, repeat.
                                  where u can see rem saudymas means shooting, on other echos it just says that either it's hit or missed. I believe other commands are in english already.

                                  Anyway, I think i just need to delete variable if it's hit and next time on picking coordinates to output message which would say that i already hit that and it no longer exist. but then still how to check weather there are any variables left?

                                  hope this helps a bit.

                                  foxidrive



                                    Specialist
                                  • Thanked: 268
                                  • Experience: Experienced
                                  • OS: Windows 8
                                  Re: naval battle game problem help
                                  « Reply #31 on: November 03, 2013, 06:51:52 AM »
                                  I do understand you, problem is, I'm not sure if I can use English in my code (you know, I'm not exchange student or anything, so why should I use it).

                                  You're posting to a forum that is in English, and asking for free help.  I think they are a good reasons. :)

                                  After it is all done you could graciously post it for others to use, and an English copy would be widely appreciated.

                                  orux

                                    Topic Starter


                                    Rookie

                                    • Experience: Beginner
                                    • OS: Windows 7
                                    Re: naval battle game problem help
                                    « Reply #32 on: November 03, 2013, 07:19:48 AM »
                                    I will post English version here once I'm done with it, but I need to finish it first :P.