Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:09:59+00:00 2026-06-13T14:09:59+00:00

Right now I am creating a connect 4 game in swing. I did not

  • 0

Right now I am creating a connect 4 game in swing. I did not post all the GUI components since it is not important. The game detects horizontal wins for all rows except the bottom row. Here is the code for the win detection.

boolean CheckForWin()
    {
        for (int row = 1; row < gameBoard.length; row++) //Plus 1 is added to prepare for dimension swap.
        { 
            //Player 1 horizontal count
            int max=0;
            //Player 2 horrizontal count
            int max2=0;
            int count_piece=0;
            for(int column=1; column<gameBoard.length; column++)
            {   
                // check for horizontal
                if(row==6)
                {
                    break;
                }
                if(count_piece<max || count_piece<max2) 
                {
                    count_piece=max;
                    count_piece=max2;
                }
                if(gameBoard[row][column]=='r')
                {
                    max++;
                }
                else
                {
                    max=0;
                }
                if(gameBoard[row][column]=='b')
                {
                    max2++;
                }
                else
                {
                    max2=0;
                }
                if(max==4 || max2==4)
                {
                    return true;
                }
      // check for vertical
            }               
        }   
      // check for diagonal up
      // check for diagonal down
      return false;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:10:00+00:00Added an answer on June 13, 2026 at 2:10 pm

    I’m assuming gameboard is an array of arrays? You are starting rows and columns at 1 in your loops but they are 0 based in java. Do you also not detect a win in the furthest left column?

    You should change your loops to for int row = 0;... and for int column = 0...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm creating an online game where I list the last transfers of
Right now I am creating a UITableView in a FlipsideView nib. I don't seem
I'm writing my first MVC app right now and am creating a new MembershipProvider
I'm writing my first MVC app right now and am creating a new MembershipProvider
Background Right now, I'm creating a multiple-predictor linear model and generating diagnostic plots to
I'm creating a form. As of right now I have simple MAILTO form that
I have a website that right now, runs by creating static html pages from
Working on creating a server/client system in C right now, and I'm having a
I want to create objects dynamically. Right now I'm creating them manually like this
I am creating an app that is a speedometer, but right now, it looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.