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 6919305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:58:23+00:00 2026-05-27T09:58:23+00:00

I am writing a dots and boxes program for a class and have most

  • 0

I am writing a dots and boxes program for a class and have most everything ready to go except I am having trouble printing the grid.

Note: The grid can be any size from 2×2 to 9×9. A two by two grid must print like this to standard out:

a + + +    //after some moves:  a +-+ +
                                  |P| 
b + + +                         b +-+ +

c + + +                         c + + +
  1 2 3                           1 2 3

I have a data structure for the dots, edges, and boxes. and the grid object has a one dimensional vector for each class.

ie dots is a vector of all of the points on the grid,
edges is a vector of all the edges on the grid (Each edge has two dots)
boxes is a vector of all the boxes on the grid (each box has four edges)

the boxes have a enum for who owns the box Player or Computer
and the edges have an bool for if they are taken or not, and also a bool for if they are vertical or not.

I am getting confused when I am trying to print the grid since the grid can be multiple sizes.

Since (size) edges print on the even(horizontal) rows, and (size+1) on the odd(vertical).

I hope I am explaining this clearly.

Thanks!

  • 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-05-27T09:58:24+00:00Added an answer on May 27, 2026 at 9:58 am

    Take your edges and lay it out in a sequence (a vector).

    gridsize = 2 : hh vvv hh vvv hh
    

    This is what you noticed with horizontal = 2 and vertical = size + 1.

    Now figure out the algorithm to get the different values for the different edges. Here is how I stored the edges into a vector based on your example:

    Your first (empty) 2x2 grid: 00 000 00 000 00
    Your second 2x2 grid:        10 110 10 000 00
    

    When I printed out the grid, I used rows and columns in for loops.

    // I consider the (row, col) to be the box.
    // Each row loop prints one horizontal line and (possibly) one vertical line.
    // Access to the edge vector is based on this (row, col) pair.
    for (int row = 0; row < size + 1; row++) /* +1 to draw the bottom line. */
    {
        if (row < size) /* Bottom most horizontal row not followed by vertical. */
            for (int col = 0; col < size + 1; col++) /* +1 to draw rightmost line. */
    }
    

    The edge going from b1 to b2 is stored in position 5 (counting from 0, count the possible edges). How do you get this position?

    You may want to stop here and figure the rest out yourself. I use pen and paper!

    The edge from b1 to b2 (according to my algorithm) is part of the second row, first column (1, 0). When printing the horizontal edges, here’s how to calculate the edge’s position in the vector.

    Horizontal edge: pos = (row * (size + size + 1)) + col
    

    The edge from a2 to b2 is part of the first row, second column (0, 2). When printing the vertical edges you need to adjust it

    Vertical edge: pos = (row * (size + size + 1)) + size + col
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing a python program, and I came up with this error while using the
Writing a lexer of .java source files in Java. I have a stream of
Writing some classes for a Framework extension, and I have the following code: public
Writing a simple program that will find exact duplicate files on my computer, but
Writing a TCL script to match everything in between two key words Example: X509v3
Writing an iPhone app in Objective-C, I have a date in string form (in
I was writing a simple program on Python 3.1 and I stumbled upon this:
Writing a file utility to strip out all non-ASCII characters from files. I have
Writing a program in which I need to split strings from a struct linked

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.