Results 1 to 6 of 6

Thread: How to build Connect4 game in C++

  1. #1
    Join Date
    Mar 2011
    Posts
    71

    How to build Connect4 game in C++

    I have a little problem with my C + + coding for my course. I have been request to schedule a game of pattern recognition and in my (almost) infinite perception; I decided to try to make a working version of Connect 4. The basic idea: I am using a 2D matrix as network gaming, all values are reset before the start of the game. The use of a selector function, the user can select which column to place your pieces in play. IF loop controls if the lower value of that column is zero (if not, another IF function loop moves to the location of a matrix above.

  2. #2
    Join Date
    Mar 2011
    Posts
    72

    Re: How to build Connect4 game in C++

    Hello having same problem. The difficulty I'm having is that I comprise no idea how to obtain the program to control the game and to detect any patterns of 4 emerge. I had thought to use two very different values and just add the rows of the matrix. However, getting the work would be very uncomfortable unless he could convince people to make my way to use only the same column again and again. Any advice or tips would be greatly appreciated. Other than bear in mind that I in reality.

  3. #3
    Join Date
    May 2009
    Posts
    527

    Re: How to build Connect4 game in C++

    Subsequent to each place of a counter, confirm to observe if a matching color counter is next to the positioned counter. If yes, continue next to that axis to observe if 4 counters are in attendance. If yes, end game through win. If no, go back in the direction of placed counter and attempt a different route. Even though this is simply basic and will merely count a row if they placed counter is at the extremely end of the row. If, say, you have this:
    0 0 0 X
    0 0 Z 0
    0 X 0 0
    X 0 0 0

    With Z being the positioned counter, after that the logic will not notice that as a row.

  4. #4
    Join Date
    Apr 2009
    Posts
    488

    Re: How to build Connect4 game in C++

    There are simply a finite number of ways for the final game (depending on the size of the table). I assume the smaller wiki name plate, 7x6. In every column there are 3 technique to win (21 columns) in every row there are 4 ways in the direction of win (24 for rows), and there are 26 dissimilar ways diagonally to win. You basically have to observe the 71 dissimilar ways a person could win. Go down each column and see if there are 4 in a row from the top, from the bottom and second from the top or lower than the second. If there is a 0 in any starting position can move to the next test. If there is an off color piece in the subsequently slot that acquire checked after that move to the next test.

  5. #5
    Join Date
    May 2009
    Posts
    539

    Re: How to build Connect4 game in C++

    If you are going to perform recursion to determine this would include a check function in the direction of check the 3-8 points approximately a single point afterward call single 8 recursive functions to recurse down an address to observe if the same colors. But the problem with this approach is that each point on the network needs to be checked. If the starting point is not the end of a line of 4 then a recursive solution completed this technique will feel the group of four. For this to perform the starting point must be on one end of group 4, which means that every point on top of the board should be reviewed.

  6. #6
    Join Date
    May 2009
    Posts
    637

    Re: How to build Connect4 game in C++

    I talked to my friend, and presented a more complex, but eventually an enhanced solution in my view. Since we do not want to produce pseudo-code for this I am going to outline his thought: build a container class that will carry out the works. Establish a list of two dimensions of these containers, type of list would probably be coded linked list. Have each container in 2 dimensions to be doubly linked lists with the other containers nearby. Make use of a container variable and process to preserve an active account longest straight chain of the similar kind of piece from every piece. This variable is actively updated when a piece is added. When the longest string line in any piece = 4 that piece's type wins.

Similar Threads

  1. Replies: 2
    Last Post: 14-05-2012, 10:56 AM
  2. How to build 2 orc squads in Zynga Warstorm Game
    By Dorkfoot in forum Video Games
    Replies: 3
    Last Post: 24-09-2011, 05:39 PM
  3. New PC Build
    By Redrob in forum Motherboard Processor & RAM
    Replies: 8
    Last Post: 23-08-2011, 12:35 PM
  4. new build PLEASE help
    By ablia in forum Hardware Peripherals
    Replies: 1
    Last Post: 19-10-2009, 10:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,509,963.98934 seconds with 17 queries