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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:14:24+00:00 2026-05-31T08:14:24+00:00

You’re trying to decide who will win a game assuming optimal choices. The idea

  • 0

You’re trying to decide who will win a game assuming optimal choices. The idea is there are x number of spaces, _ _ _ _ _ _ _. Player one goes and marks two consecutive spots. Then player two goes and does the same. The first player who cannot go WINS. So given the board before, this is one possiblity:

P1: x x _ _ _ _ _

P2: x x _ x x _ _

P1: x x _ x x x x

So player 2 wins. You’re given an array where 0 represents a free space and 1 represents a marked spot. The array may have some spots already marked.

The only way I can think to do this is check every move, and for every move check if every possible move after results in a win. I can’t even fully figure out how I would do this, but I was hoping there was a better way. Any ideas?

  • 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-31T08:14:25+00:00Added an answer on May 31, 2026 at 8:14 am

    You should work problems like this backwards.

    Given all the possible game states, go through and decide which is a win for player 1 (W) and which is a win for player 2 (L). Initially, you only know the answer for the states where no one can play. In this case the answer is

    • W if no two consecutive spots and total number of taken spots is 4k
    • L if no two consecutive spots and total number of taken spots is 4k+2

    Now work backwards. If there is any board position from which player 1 can move to a W, mark that as W, and if there is any board position from which player 2 can move to a L, mark that as L. Again, this won’t get all positions marked right away, but iterating this will. The iterative part is this

    • W if there are 4k+2 spots and two consecutive spots which, when filled, give position marked W
    • L if there are 4k spots and two consecutive spots which, when filled, give position marked L

    Example: Consider the board _ _ _ _ _ _. Evaluate from the final states working backwards

    Player Two to move:

    X X X X X X (L - terminal)
    

    Player One to move:

    X X _ X X _ (W - terminal)
    _ X X _ X X (W - terminal)
    _ X X X X _ (W - terminal)
    X X X X _ _ (L - must move to X X X X X X)
    _ _ X X X X (L - must move to X X X X X X)
    

    Player Two to move:

    X X _ _ _ _ (L - can move to X X X X _ _) 
    _ X X _ _ _ (W - must move to _ X X _ X X or _ X X X X _)
    _ _ X X _ _ (L - can move to X X X X _ _)
    _ _ _ X X _ (W - must move to X X _ X X _ or _ X X X X _)
    _ _ _ _ X X (L - can move to X X _ _ X X)
    

    Player One to move:

    _ _ _ _ _ _ (W - can move to _ X X _ _ _)
    

    You can program this recursively so that each position will be evaluated as W or L. Let each board position P be represented by a binary vector of length n where 1 denotes a taken spot and 0 denotes an open spot. Here’s the pseudocode for doesPlayerOneWin:

    // STORE NUMBER OF ONES
    int m = 0;
    for (int i=0; i<n; ++i)
        m += P[i];
    // LOOK FOR LEGAL MOVES
    bool canMove = false;
    for (int i=0; i<n-1; ++i)
        int[] newP = P;
        if (P[i]+P[i+1] == 0) {
            canMove = true;
            newP[i] = 1;
            newP[i+1] = 1;
            // PLAYER ONE CAN MOVE TO WIN
            if (m % 4 == 0 && doesPlayerOneWin(newP))
                return true;
            // PLAYER TWO CAN MOVE TO WIN
            if (m % 4 == 2 && !doesPlayerOneWin(newP))
                return false;
         }
    }
    // IF NO LEGAL MOVES, PLAYER TO MOVE WINS
    if (!canMove && m % 4 == 0)
        return true;
    else if (!canMove && m % 4 == 2)
        return false;
    // OTHERWISE IF LOOP RUNS, PLAYER TO MOVE LOSES
    if (m % 4 == 0)
        return false;
    else
        return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.