Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. The first descent code I wrote in my life

The first descent code I wrote in my life

Scheduled Pinned Locked Moved The Lounge
c++game-devalgorithmsdata-structureslounge
40 Posts 27 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vasily Tserekh

    This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

    //------Check if in square X;Y a ship can be placed------------------

    /* x,y: Board coordinates
    Size: Ship size
    Pos: posicion (1 horizontal vertical)
    board: board number
    */
    bool TGame::Free(int x,int y,int size,int pos,int board )
    {
    int ship[7];
    int side1[7];
    int side2[7];
    bool answer=true;
    if(aBoard[board]->GetInfo(x,y)!=0)
    {
    return answer=false;
    }
    if (pos==1)
    {
    for(int i=0;i<size+2;i++)
    {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
    side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
    side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
    }
    }

    else
    { for(int i=0;i<size+2;i++)
    {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
    side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
    side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
    }
    }
    if (x==0 && pos==1)
    {ship[0]=0;
    side1[0]=0;
    side2[0]=0;

    }
    for (int i=0;i<size+2;i++)
    {if (ship[i]!= 0)answer=false;
    if (side1[i]!= 0)answer=false;
    if (side2[i]!= 0)answer=false;
    }
    return answer;
    }
    //------Place a ship in the board-------------------------------------

    /* Size: Ship size
    board: Board
    Ship: Place of the ship in the ship array
    Type: ship type
    */
    void TGame:: RandomShip(int size,int type,int board,int ship)
    {
    int pos=random(2);
    randomize();
    int x,y;
    bool answer=false; ;
    if (pos==1)
    {
    while (answer==false)
    {
    x=random(11)-size;
    while(x<0)
    {x=random(11)-size;
    }
    y=random(15);
    answer=Free(x,y,size,pos,board);
    }
    for(int i=0;i<size;i++)
    {aBoard[board]->SetInfo(x+i,y,type);
    }
    }
    else
    {
    while (answer==false)
    {
    x=random(10);
    y=random(16)-size;
    while(y<0)
    {y=random(16)-size;
    }
    answer=Free(x,y,size,pos,board);
    }
    for(int i=0;i<size;i++)
    {aBoard[board]->SetInfo(x,y+i,type);
    }
    }
    if(board==0)
    {
    int ax=Transfo

    P Offline
    P Offline
    pontellen
    wrote on last edited by
    #31

    Just out of college, I wanted to use something from the data structures class so wrote a right-inthreaded binary tree structure by hand to handle a large data set. Each unique number went to it's own leaf with a count. In the end, I could traverse the tree, generating a histogram and various statistics, st dev, etc as desired. I think it was in HP Basic predating the PC era at our workplace.

    1 Reply Last reply
    0
    • V Vasily Tserekh

      This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

      //------Check if in square X;Y a ship can be placed------------------

      /* x,y: Board coordinates
      Size: Ship size
      Pos: posicion (1 horizontal vertical)
      board: board number
      */
      bool TGame::Free(int x,int y,int size,int pos,int board )
      {
      int ship[7];
      int side1[7];
      int side2[7];
      bool answer=true;
      if(aBoard[board]->GetInfo(x,y)!=0)
      {
      return answer=false;
      }
      if (pos==1)
      {
      for(int i=0;i<size+2;i++)
      {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
      side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
      side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
      }
      }

      else
      { for(int i=0;i<size+2;i++)
      {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
      side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
      side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
      }
      }
      if (x==0 && pos==1)
      {ship[0]=0;
      side1[0]=0;
      side2[0]=0;

      }
      for (int i=0;i<size+2;i++)
      {if (ship[i]!= 0)answer=false;
      if (side1[i]!= 0)answer=false;
      if (side2[i]!= 0)answer=false;
      }
      return answer;
      }
      //------Place a ship in the board-------------------------------------

      /* Size: Ship size
      board: Board
      Ship: Place of the ship in the ship array
      Type: ship type
      */
      void TGame:: RandomShip(int size,int type,int board,int ship)
      {
      int pos=random(2);
      randomize();
      int x,y;
      bool answer=false; ;
      if (pos==1)
      {
      while (answer==false)
      {
      x=random(11)-size;
      while(x<0)
      {x=random(11)-size;
      }
      y=random(15);
      answer=Free(x,y,size,pos,board);
      }
      for(int i=0;i<size;i++)
      {aBoard[board]->SetInfo(x+i,y,type);
      }
      }
      else
      {
      while (answer==false)
      {
      x=random(10);
      y=random(16)-size;
      while(y<0)
      {y=random(16)-size;
      }
      answer=Free(x,y,size,pos,board);
      }
      for(int i=0;i<size;i++)
      {aBoard[board]->SetInfo(x,y+i,type);
      }
      }
      if(board==0)
      {
      int ax=Transfo

      R Offline
      R Offline
      Reese Currie
      wrote on last edited by
      #32

      My story is from a long time ago--probably 1989. I'd been hired by a small consulting shop as a COBOL programmer. My favorite language, however, was C and I worked it into my job as frequently as I could. In these days before Perl and Python, all of my quick knock-off "scripts" were C programs. My day-to-day working computer was a Unisys 6000/30 running CTIX, Unisys' version of UNIX System V, and the accounting software. I was connected to it with a dumb terminal; others were connected by dumb terminals or PC's over serial cables. The company charged meticulously for time spent consulting, including phone time. To make tracking that time easier, the boss had installed a phone system that tracked time on incoming calls, and when calls completed, sent the details to a serial printer. The trouble was, the paper would bind up in that printer all the time and calls would end up going uncharged. One day the boss was extra ticked off because the paper had been jammed up for days and no one had noticed. Hm, I thought; it's a serial interface, and the printer was only maybe 8 feet closer to the phone box than the Unisys was, and I had three serial ports free. How about a daemon to poll the serial port and put the results in a file, and eliminate the serial printer? I proposed the idea to the boss and he allowed me to work on it on a low priority basis when client demands allowed. So I figured out how to configure and read serial ports from C, and had my serial printer substitute available in two or three days. The boss and the girls in accounting were extremely happy about it. They requested me to write some utilities to look up particular phone numbers in the file and so forth, all of which I did in C. The cool part, though, was interfacing to the printer, back in a day when you couldn't just look up how to do things on the Net, but had to actually read the voluminous manuals that came with your system and piece the concepts together yourself.

      P 1 Reply Last reply
      0
      • V Vasily Tserekh

        This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

        //------Check if in square X;Y a ship can be placed------------------

        /* x,y: Board coordinates
        Size: Ship size
        Pos: posicion (1 horizontal vertical)
        board: board number
        */
        bool TGame::Free(int x,int y,int size,int pos,int board )
        {
        int ship[7];
        int side1[7];
        int side2[7];
        bool answer=true;
        if(aBoard[board]->GetInfo(x,y)!=0)
        {
        return answer=false;
        }
        if (pos==1)
        {
        for(int i=0;i<size+2;i++)
        {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
        side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
        side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
        }
        }

        else
        { for(int i=0;i<size+2;i++)
        {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
        side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
        side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
        }
        }
        if (x==0 && pos==1)
        {ship[0]=0;
        side1[0]=0;
        side2[0]=0;

        }
        for (int i=0;i<size+2;i++)
        {if (ship[i]!= 0)answer=false;
        if (side1[i]!= 0)answer=false;
        if (side2[i]!= 0)answer=false;
        }
        return answer;
        }
        //------Place a ship in the board-------------------------------------

        /* Size: Ship size
        board: Board
        Ship: Place of the ship in the ship array
        Type: ship type
        */
        void TGame:: RandomShip(int size,int type,int board,int ship)
        {
        int pos=random(2);
        randomize();
        int x,y;
        bool answer=false; ;
        if (pos==1)
        {
        while (answer==false)
        {
        x=random(11)-size;
        while(x<0)
        {x=random(11)-size;
        }
        y=random(15);
        answer=Free(x,y,size,pos,board);
        }
        for(int i=0;i<size;i++)
        {aBoard[board]->SetInfo(x+i,y,type);
        }
        }
        else
        {
        while (answer==false)
        {
        x=random(10);
        y=random(16)-size;
        while(y<0)
        {y=random(16)-size;
        }
        answer=Free(x,y,size,pos,board);
        }
        for(int i=0;i<size;i++)
        {aBoard[board]->SetInfo(x,y+i,type);
        }
        }
        if(board==0)
        {
        int ax=Transfo

        B Offline
        B Offline
        BrainiacV
        wrote on last edited by
        #33

        Golly I've written so many, I can't remember. :cool: In high school I wrote a program that would automatically locate roots of an equation. The assignment was to key in the formula and then sit through the output of a FOR/NEXT looking for sign reversals and unless you hit zero, go back over the range where the reversal occurred at a smaller step. I said screw that, and wrote a program the automated the process and used a stack like process to evaluate the list of sign reversals the initial sweep would locate. The math teacher always bitched me out because he thought I should have been staring at formulas in the textbook rather than running down to the computer room and actually putting them to work. :omg: But this time I impressed him and he posted my program on the bulletin board. My first professional program that I wrote that impressed even me, was the one I wrote to process the phone billing tape for corporate headquarters. I had seen the other programmers get bogged down having to do support work every month on previous programs they had written and I vowed never to fall into that trap. To achieve that, I found already existing databases that other departments maintained and tapped into them for the information I needed. I made the processing a double pass, the first to collect charges and the second to divide them up. The "older and wiser" heads told me to just toss in constants, but I wanted something that would self adjust and never need maintenance. In the end, if the program couldn't figure out where a charge was to go, a human couldn't either. Elements that were not recognized were sent to an error report and through that we found the phone company had been over billing us about $5000.00 a month for years. But the feature that really makes me smile was when after I had left the company, they wanted to expand the number of facilities it would generate the department billing for. The person who inherited my program told them to just run the augmented tape through the program and he'd look through the error report to estimate what changes would need to be made. He called me afterwards to tell me the program did not need any changes, it figured it out by itself. I about flew around the room in happiness. :) :) :) :) :)

        Psychosis at 10 Film at 11 Those who do not remember the past, are doomed to repeat it. Those who do not remember the past, cannot build upon it.

        1 Reply Last reply
        0
        • R Reese Currie

          My story is from a long time ago--probably 1989. I'd been hired by a small consulting shop as a COBOL programmer. My favorite language, however, was C and I worked it into my job as frequently as I could. In these days before Perl and Python, all of my quick knock-off "scripts" were C programs. My day-to-day working computer was a Unisys 6000/30 running CTIX, Unisys' version of UNIX System V, and the accounting software. I was connected to it with a dumb terminal; others were connected by dumb terminals or PC's over serial cables. The company charged meticulously for time spent consulting, including phone time. To make tracking that time easier, the boss had installed a phone system that tracked time on incoming calls, and when calls completed, sent the details to a serial printer. The trouble was, the paper would bind up in that printer all the time and calls would end up going uncharged. One day the boss was extra ticked off because the paper had been jammed up for days and no one had noticed. Hm, I thought; it's a serial interface, and the printer was only maybe 8 feet closer to the phone box than the Unisys was, and I had three serial ports free. How about a daemon to poll the serial port and put the results in a file, and eliminate the serial printer? I proposed the idea to the boss and he allowed me to work on it on a low priority basis when client demands allowed. So I figured out how to configure and read serial ports from C, and had my serial printer substitute available in two or three days. The boss and the girls in accounting were extremely happy about it. They requested me to write some utilities to look up particular phone numbers in the file and so forth, all of which I did in C. The cool part, though, was interfacing to the printer, back in a day when you couldn't just look up how to do things on the Net, but had to actually read the voluminous manuals that came with your system and piece the concepts together yourself.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #34

          Reese Currie wrote:

          the girls in accounting were extremely happy

          Oh, that reminds me of the program I wrote for the girl in the college placement office -- she married me. :-D Twenty years and counting. :jig:

          R 1 Reply Last reply
          0
          • V Vasily Tserekh

            This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

            //------Check if in square X;Y a ship can be placed------------------

            /* x,y: Board coordinates
            Size: Ship size
            Pos: posicion (1 horizontal vertical)
            board: board number
            */
            bool TGame::Free(int x,int y,int size,int pos,int board )
            {
            int ship[7];
            int side1[7];
            int side2[7];
            bool answer=true;
            if(aBoard[board]->GetInfo(x,y)!=0)
            {
            return answer=false;
            }
            if (pos==1)
            {
            for(int i=0;i<size+2;i++)
            {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
            side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
            side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
            }
            }

            else
            { for(int i=0;i<size+2;i++)
            {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
            side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
            side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
            }
            }
            if (x==0 && pos==1)
            {ship[0]=0;
            side1[0]=0;
            side2[0]=0;

            }
            for (int i=0;i<size+2;i++)
            {if (ship[i]!= 0)answer=false;
            if (side1[i]!= 0)answer=false;
            if (side2[i]!= 0)answer=false;
            }
            return answer;
            }
            //------Place a ship in the board-------------------------------------

            /* Size: Ship size
            board: Board
            Ship: Place of the ship in the ship array
            Type: ship type
            */
            void TGame:: RandomShip(int size,int type,int board,int ship)
            {
            int pos=random(2);
            randomize();
            int x,y;
            bool answer=false; ;
            if (pos==1)
            {
            while (answer==false)
            {
            x=random(11)-size;
            while(x<0)
            {x=random(11)-size;
            }
            y=random(15);
            answer=Free(x,y,size,pos,board);
            }
            for(int i=0;i<size;i++)
            {aBoard[board]->SetInfo(x+i,y,type);
            }
            }
            else
            {
            while (answer==false)
            {
            x=random(10);
            y=random(16)-size;
            while(y<0)
            {y=random(16)-size;
            }
            answer=Free(x,y,size,pos,board);
            }
            for(int i=0;i<size;i++)
            {aBoard[board]->SetInfo(x,y+i,type);
            }
            }
            if(board==0)
            {
            int ax=Transfo

            R Offline
            R Offline
            RafagaX
            wrote on last edited by
            #35

            The first code i wrote i'm proud of, is an invoice system that i made following almost to the letter the Object Oriented approach... in PHP, having said that, i would never ever do that again, it was a terrible experience given the quirks on the OO implementation of PHP, however, the system is easily extensible once you get to know any of the modules (they all look and work the same).

            CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Reese Currie wrote:

              the girls in accounting were extremely happy

              Oh, that reminds me of the program I wrote for the girl in the college placement office -- she married me. :-D Twenty years and counting. :jig:

              R Offline
              R Offline
              Reese Currie
              wrote on last edited by
              #36

              Awesome! I went out with one of these girls' sisters for a while, but it was unrelated to having provided code ... :laugh:

              1 Reply Last reply
              0
              • P PIEBALDconsult

                Mine took 7.5 million years to execute and simply said "42". :-\

                R Offline
                R Offline
                Ranjan D
                wrote on last edited by
                #37

                Were dinosaurs exist when you were running your code ;P

                Ranjan.D

                1 Reply Last reply
                0
                • V Vasily Tserekh

                  This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

                  //------Check if in square X;Y a ship can be placed------------------

                  /* x,y: Board coordinates
                  Size: Ship size
                  Pos: posicion (1 horizontal vertical)
                  board: board number
                  */
                  bool TGame::Free(int x,int y,int size,int pos,int board )
                  {
                  int ship[7];
                  int side1[7];
                  int side2[7];
                  bool answer=true;
                  if(aBoard[board]->GetInfo(x,y)!=0)
                  {
                  return answer=false;
                  }
                  if (pos==1)
                  {
                  for(int i=0;i<size+2;i++)
                  {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
                  side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
                  side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
                  }
                  }

                  else
                  { for(int i=0;i<size+2;i++)
                  {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
                  side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
                  side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
                  }
                  }
                  if (x==0 && pos==1)
                  {ship[0]=0;
                  side1[0]=0;
                  side2[0]=0;

                  }
                  for (int i=0;i<size+2;i++)
                  {if (ship[i]!= 0)answer=false;
                  if (side1[i]!= 0)answer=false;
                  if (side2[i]!= 0)answer=false;
                  }
                  return answer;
                  }
                  //------Place a ship in the board-------------------------------------

                  /* Size: Ship size
                  board: Board
                  Ship: Place of the ship in the ship array
                  Type: ship type
                  */
                  void TGame:: RandomShip(int size,int type,int board,int ship)
                  {
                  int pos=random(2);
                  randomize();
                  int x,y;
                  bool answer=false; ;
                  if (pos==1)
                  {
                  while (answer==false)
                  {
                  x=random(11)-size;
                  while(x<0)
                  {x=random(11)-size;
                  }
                  y=random(15);
                  answer=Free(x,y,size,pos,board);
                  }
                  for(int i=0;i<size;i++)
                  {aBoard[board]->SetInfo(x+i,y,type);
                  }
                  }
                  else
                  {
                  while (answer==false)
                  {
                  x=random(10);
                  y=random(16)-size;
                  while(y<0)
                  {y=random(16)-size;
                  }
                  answer=Free(x,y,size,pos,board);
                  }
                  for(int i=0;i<size;i++)
                  {aBoard[board]->SetInfo(x,y+i,type);
                  }
                  }
                  if(board==0)
                  {
                  int ax=Transfo

                  I Offline
                  I Offline
                  IndifferentDisdain
                  wrote on last edited by
                  #38

                  Not my first bit of decent code, but perhaps the first bit that my boss said "Hey, that's pretty cool"; I had to write a utility to compare values in a database to those in a file, but the file values often had extra precision, so a quick compare would throw a bunch of false negatives. So, I wrote the method below, and it worked swimmingly well:

                  public static bool AreValuesRoughlyEqual(decimal? firstValue, decimal? secondValue) {

                       // Quick check for performance if they're equal
                       if (firstValue == secondValue) {
                          return true;
                       }
                  
                       // If one is null and the other is not, return false.
                       if (!firstValue.HasValue && secondValue.HasValue)
                          return false;
                       if (firstValue.HasValue && !secondValue.HasValue)
                          return false;
                  
                       bool retVal = false;    // Assume values are not equal, will set to equal if we hit something valid.
                  
                       // Now we know both params have values; we need to check if one has greater precision than the other.
                       string tempNum = Convert.ToString(firstValue.Value);
                       int numbersToLeft = tempNum.IndexOf(".") + 1;   // This gives us the # of values to the left of the decimal + 1 for the decimal.
                       int firstValuePrecision = tempNum.Length - numbersToLeft;  // The precision of the first value.
                       tempNum = Convert.ToString(secondValue.Value);
                       numbersToLeft = tempNum.IndexOf(".") + 1;
                       int secondValuePrecision = tempNum.Length - numbersToLeft;  // The precision of the second value.
                  
                       // We're going to modify these values, but we don't know which one yet, so just initialize for now.
                       decimal firstValueForComparison = firstValue.Value;
                       decimal secondValueForComparison = secondValue.Value;
                  
                       // first value is too precise, round/chop it off to be the same as the second number.
                       if (firstValuePrecision > secondValuePrecision) {
                          // try rounding first
                          if (secondValueForComparison == Math.Round(firstValueForComparison, secondValuePrecision, MidpointRounding.AwayFromZero)) {
                             retVal = true;
                          }
                          else {
                             // Amazingly, there's no real easy way to truncate a decimal to a specific number of placed that I could find.
                             // So, this works: basically, multiply by powers of 1,000 so that you move the decimal to the right for all 
                             // numbers that you want to keep, get rid of the extra, then move the dec
                  
                  1 Reply Last reply
                  0
                  • V Vasily Tserekh

                    This is the first descent code I wrote when I began to make programs, it was in C++ Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then. How about you

                    //------Check if in square X;Y a ship can be placed------------------

                    /* x,y: Board coordinates
                    Size: Ship size
                    Pos: posicion (1 horizontal vertical)
                    board: board number
                    */
                    bool TGame::Free(int x,int y,int size,int pos,int board )
                    {
                    int ship[7];
                    int side1[7];
                    int side2[7];
                    bool answer=true;
                    if(aBoard[board]->GetInfo(x,y)!=0)
                    {
                    return answer=false;
                    }
                    if (pos==1)
                    {
                    for(int i=0;i<size+2;i++)
                    {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
                    side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
                    side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
                    }
                    }

                    else
                    { for(int i=0;i<size+2;i++)
                    {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
                    side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
                    side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
                    }
                    }
                    if (x==0 && pos==1)
                    {ship[0]=0;
                    side1[0]=0;
                    side2[0]=0;

                    }
                    for (int i=0;i<size+2;i++)
                    {if (ship[i]!= 0)answer=false;
                    if (side1[i]!= 0)answer=false;
                    if (side2[i]!= 0)answer=false;
                    }
                    return answer;
                    }
                    //------Place a ship in the board-------------------------------------

                    /* Size: Ship size
                    board: Board
                    Ship: Place of the ship in the ship array
                    Type: ship type
                    */
                    void TGame:: RandomShip(int size,int type,int board,int ship)
                    {
                    int pos=random(2);
                    randomize();
                    int x,y;
                    bool answer=false; ;
                    if (pos==1)
                    {
                    while (answer==false)
                    {
                    x=random(11)-size;
                    while(x<0)
                    {x=random(11)-size;
                    }
                    y=random(15);
                    answer=Free(x,y,size,pos,board);
                    }
                    for(int i=0;i<size;i++)
                    {aBoard[board]->SetInfo(x+i,y,type);
                    }
                    }
                    else
                    {
                    while (answer==false)
                    {
                    x=random(10);
                    y=random(16)-size;
                    while(y<0)
                    {y=random(16)-size;
                    }
                    answer=Free(x,y,size,pos,board);
                    }
                    for(int i=0;i<size;i++)
                    {aBoard[board]->SetInfo(x,y+i,type);
                    }
                    }
                    if(board==0)
                    {
                    int ax=Transfo

                    T Offline
                    T Offline
                    Thornik
                    wrote on last edited by
                    #39

                    My first code I was proud of was quite simple: 10 CIRCLE (100,100), 50 As in well known story, it was "small step for a computer, but big step for a human" - this line gave me a whole picture of programming: "I say, it does". This was crucial moment when I choose my profession (and fate actually).

                    1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      My first descent code was a recursive descent parser[^]. I'm not sure if it was decent, though! ;P


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      M Offline
                      M Offline
                      Member 4608898
                      wrote on last edited by
                      #40

                      I too thought the first recursive descent parser I ever wrote was absolutely amazing.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups