Computer not blocking my attempt

Select computer mode and press 0 until the computer stacks one on top of the 0 column.. Then try to get 4 in a row as scuh
BLANK
X
X
X
O
X
Look at my computerMove() method. I basically copied my win() methods beginning part and it should be blocking. Why isn't it!?!?!?!?!
Edit-Code too long. I'll post half here half in the next
     import java.util.Scanner;//Input for user
     import java.util.Random;//Computer Generator turn
     public class connect4
   //These 2 variables are set to false, if it is set to true then they win.
      public static int rows=6;//Used to make the board
      public static int columns=7;
      public static boolean firstTime=true;//For the printBoard() method. If it's the first time it writes the board.
      public static String[][] gameBoard=new String[rows][columns];//2D array for the board.
      public static String userSwitch="";
          public static int firstCompMove=0;//For the compMove() method. Makes a random move the first time
          public static void main(String args[])
               Scanner input=new Scanner(System.in);
               Use a for loop to have the player input stuff via the play method
               send that data once it is transfered to the move method and then
               keep doing it until all spaces are filled or a winner is decided
               which is decided via the win method
               //Welcoming user, etc.
         System.out.println("   Welcome to Connect Four");
         printBoard(true);
               String computerOrPlayer="";
               //Whether the player1 wants to face player2 or a computer
               while(!computerOrPlayer.equalsIgnoreCase("c") && !computerOrPlayer.equalsIgnoreCase("p"))
                    System.out.println("Would you like to have player 2 or a computer? Type 'C' for computer or 'P' for player 2");
                  //Gets the user input, uppercased, and the first character     
                    computerOrPlayer=input.nextLine().toUpperCase().substring(0,1);
               String switching="_X_";
               //While the program isn't exited
               while(play(input, switching, computerOrPlayer).equals(""))
                    //Keep switching turns
                    if(switching.equals("_X_"))
                         switching="_O_";
                    else if(switching.equals("_O_"))
                         switching="_X_";
          //Method to print the board
          public static void printBoard(boolean firstTime)
         System.out.println("  0   1   2   3   4   5   6");
         for(int i=0;i<rows;i++)
            for(int j=0;j<columns;j++)
               if(firstTime)
                  gameBoard[i][j]="___";
               if(j==rows)
                  System.out.println("|"+gameBoard[i][j]+"|");
               else
                  System.out.print("|"+gameBoard[i][j]);
               //This way it won't write it again later.
         firstTime=false;
          

I have a number of suggestions.
1) When posting questions to forums do post your code here and if it's a too long that's a sign you should be posting less of it. You should have started by posting the computerMove method here. Make it easy for us to help you.
2) There are a few suggestions I have about the code in general and improvements you should look to make. Many of the things you are doing are fine for beginners but as code grows in length and programs in complexity it's time to learn better styles. And you're at that point here (the use of recursion for example is a sign). The program could use a serious OO overhaul, you will learn to be a better programmer and it will make your code easier to follow and understand for you. On that note for example there is too much static here. A properly written version of this program will have exactly one static method (main) and none of the static variables. That would be a good place to start improving. If you're not sure what this means see [http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html]
3) In the same line as above, think about using a class (or enum) to represent each "square" rather than the Strings. Strings are fine for display but you don't want to abuse them by using them to hold game (object) state as well. The code would really be helped by using an enum like
public enum Square{X,O,EMPTY}See [http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html]
4) And also as above don't declare and initialize variables you may or may not need in areas removed from where you may or may not need them. Aka that random should be created the line before you need it, when you need it. Putting it at the start of the method just makes for needless confusion in reading your code and also has a negative performance impact (probably very small but it's there). You should strive to always create and use variables in the smallest scope that they need, tis good practice.
5) I suspect your actual problem is here (inside computerMove)
else if(vert==2 && horz==6)
  computerMove(0, 5, 1);
else if(vert==2 && horz<=6)
  computerMove(horz+1, 5, 0);
}It took me a bit to understand that you are looping with recursion here (and a bunch of these if/else statements) but that ending zero (aka computerMove(horz+1, 5, 0); ) looks wrong to me. Shouldn't that also be 1 there?

Similar Messages

  • With Firefox as my default browser for a desktop iMac, a note appears "An attempt to change your home page and default search has been blocked" It won't go away

    With Firefox as my default browser for a desktop iMac, a note appears "An attempt to change your home page and default search has been blocked" It won't go away. It tells me to click on the checkmark to change settings but that doesn't work and the red x in the upper right hand corner doesn't remove the note which is in the upper left corner of my iMac ??? The only thing that removes the note is quitting Firefox but it reappear as soon as I start Firefox back up ???

    If that does not work,
    Start '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Firefox in Safe Mode]''' {web Link} by holding down the '''<Shift><br> ''(Mac Options)'' ''' key, and then starting Firefox. Is the problem still there?
    Start your '''Computer''' in safe mode with networking. Then start Firefox. Try '''Safe''' web sites.
    '''[http://encyclopedia2.thefreedictionary.com/Linux+Safe+Mode Starting The Computer In Safe Mode;<br>Free Online Encyclopedia]'''

  • Prompted to upgrade iTunes on computer. Won't let me and get error message MSVVR80.dll not found. Attempted to reinstall, won't let me. Can you have iTunes and iCloud on the same computer?

    Prompted to upgrade iTunes on computer. Won't let me and get error message MSVVR80.dll not found. Attempted to reinstall, won't let me. Can you have iTunes and iCloud on the same computer?

    Try following the instructions of tt2 in https://discussions.apple.com/thread/5822086

  • How do you change the drive that my Iphone backs-up to on my computer?  My first attempt to back-up and i received a pop-up stating that I do not have sufficient memory/space, knowing that I have over 120GB of free space...any ideas? thanks

    How do you change the drive that my Iphone backs-up to on my computer?  My first attempt to back-up and i received a pop-up stating that I do not have sufficient memory/space, knowing that I have over 120GB of free space...any ideas? thanks

    dave0915,
    iTunes stores your iPhone backups in the Library folder in your Home folder.
    iTunes places the backup files in these places:
    Mac: ~/Library/Application Support/MobileSync/Backup/
    Create and delete iPhone, iPad, and iPod touch backups in iTunes
    http://support.apple.com/en-us/HT4946
    Regards,
    Allen

  • HT204406 I subscribed to iTunes Match on iTunes on my computer.  When I attempt to turn on iTunes March on my iPhone 3Gs I receive the message "You are not currently subscribed to iTunes Match.  Use iTunes on your computer to subscribe.

    I subscribed to iTunes Match on iTunes on my computer.  When I attempt to turn on iTunes Match on my iPhone 3Gs I receive the message "You are not currently subscribed to iTunes Match.  Use iTunes on your computer to subscribe"  What do I need to do to turn Match on on my phone?  Thanks

    I figured it out!  Thanks

  • When I Leave A Certain Site, It Gives The Message: "The Browser Has Blocked An Attempt To Log Out Of The Application Properly" .

    Blocked An Attempt To Log Out Of The Application Properly". How Do I FIX This

    Sometimes a problem with Firefox may be a result of malware installed on your computer, that you may not be aware of.
    You can try these free programs to scan for malware, which work with your existing antivirus software:
    * [http://www.microsoft.com/security/scanner/default.aspx Microsoft Safety Scanner]
    * [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware]
    * [http://support.kaspersky.com/faq/?qid=208283363 TDSSKiller - AntiRootkit Utility]
    [http://windows.microsoft.com/MSE Microsoft Security Essentials] is a good permanent antivirus for Windows 7/Vista/XP if you don't already have one.
    Further information can be found in the [[Troubleshoot Firefox issues caused by malware]] article.
    Did this fix your problems? Please report back to us!

  • My computer crashed after an attempt to upgrade to Yosemite. I can't quit the installer and my MacBook keeps on restarting

    My computer crashed after an attempt to upgrade to Yosemite. I can't quit the installer and my MacBook keeps on restarting

    I Have a 2008 Macbook Pro 15". It was running issue free until I upgraded to Yosemite. Now my logic board is fried and apple will not fix it. It started with mail accounts unable to send mail, just had to delete accounts and re- install to fix that. But, at the same time as the download, I started intermittently getting a green tint over the screen along with a snowy static like an old TV set. Fearing that my download was corrupt, I re- installed Yosemite over-writing the previous version .  The green haze kept coming and going, but I also started getting strobe style white flashes in boxes in the 4 corners of my monitor. I had to do power button forced shutdowns because of pointer and keyboard function failure. Apple Genius desk told me it appeared to be a logic board failure but my computer was too old for them to work onand referred me to a Mac Specialist Center. I was told by both places that Apple installed defective logic boards back then due to changing solder formula. They extended product warranty by adding 1 yr but that still expired in 2012. I tried to post a warning on Mac Forums twice about Yosemite being a poison pill to certain platforms and my posts were pulled. The second attempt was responded to in my personal email account stating that if I don't stop posting derogatory comments, I will be blocked from forum. I am just trying to insert warnings in posts where I can. They haven't discovered that yet. Spread the word!

  • Ipod frozen ("Do not disconnect") Restore attempt triggers error message

    The sequence of events:
    1. ITunes did not recognize my Ipod this morning (My ipod icon did not appear in itunes)
    2. Itunes froze. (Computer froze generally)
    During attempts to restart computer, realized that computer failed to start if Ipod firewall cord is plugged in--so I unplugged the ipod. "Do not disconnect" in ipod window.
    3. Read "Ipod The Missing Manual" fix for this disconnect problem, but does not work. Part of the problem is that my ipod still hasn't appeared in itunes, alhtough the computuer makes a familiar "dong" sound when the cable is plugged in.
    4. Figure I will attempt "system restore" for ipod during the brief period Itunes is unfrozen (thawed) immediately after I've restarted the computer. Ipod finally appears in Itunes (which takes 10 minutes to open) It does recognize an ipod--but it doesn't have my name on it. And there's a New message, that my ipod is corrupted and I must restore it, lose songs, etc. So what. Onward.
    5. Attempt to restore also unsuccessful. A new, sick-making message: "There was a problem downloading the ipod software for the ipod. The requested resource was not found."
    I've tried a new cable, tried a new port...
    Ipod is one year old. What does any of this mean? Where do I go to begin finding a solution? Do I throw it out and start again? Obviously my computer is botched up, too. What a mess.

    I have the same... and so many others and no one has a solution (up to now). It might has something to do with itunes 7th version. I have tried EVERYTHING (believe me: the 5 R's/ other Itunes versions / winamp / reboot/ reinstall/ restore/ update/ other port/ etc etc/ searched this forum)
    So many people having this problem, though Apple has not reacted on this yet...
    despite asking 180 euro's service costs if you want to resolve this by sending this item. Great

  • My computer is blocking

    about 2 weeks ago my itunes started to work very bad and about 1 week ago ,when i was trying to use itunes my computer blocked.i restarted it but it kept like this.now my computer is blocking even if itunes is not opened.the problem is getting very serious because i restarted the computer today about 15 times in a row till it started.it keeped on blocking
    Windows XP

    I wish I could adequately describe my frustration with apple. Anyway, my iphone 3gs gets nothing but an apple symbol, never getting to a red slider. On a different computer, it tells me I must overcome the passcode, Ingenious!!! I'm painstakingly extracting photos from it a few at a time. I thought it was backed up before but it wasn't so. My phone cycles off and on every few minutes making backup and restore impossible or so I thought. Though it didn't restore, it does say there's a backup. I'd like to know if it's a full backup of all the data on my phone and how do I determine that? I tried to change a contacts file to a file that could be used outside of Itunes (csv) but no luck. I feel like I'm in the twilight zone. I'm sure my iphone is not repairable as I've tried it all. Sigh

  • Safari will NOT block cookies, ever

    Safari will NOT block cookies, ever.  No matter what they always show up (even from advertisers on a particular site) - I have reset safari, deleted its preference file, re-installed the OS, tried a different user, tried as root user - all with same same result.  I tried to re-install Safari but was told by the OS that I need to have at least 10.6.7 installed and I am currently running 10.6.8!
    I have an 27" iMac running 10.6.8 with all updates, Safari 5.05.  I am also running VirusBarrier X6 10.6.12.  VirusBarrier has a cookie feature as well but it doesn't block cookies.  I have completely disabled VirusBarrier and still get the same results.
    Any help would be greatly appreciated.  Thanks.

    This is true.  The "block cookies always" setting in the Privacy tab is not 100% effective (evidently Apple programmers have their own definition of "always").
    There will not be a solution from Apple. They don't care. Users that want to block cookies are almost surely poor consumers and probably troublemakers too.
    dfp mbp's fix will work but what a pain.
    It used to be one was willing to pay the Apple "tax" for a superior product, but that was then ...
    Make your next computer a PC that runs Linux.

  • Workflow Start "Failed But Not Blocking Correlation" - Project Server workflow for Demand Management

    Hi,
    I'm trying to "Create a Project Server workflow for Demand Management" with project server 2013 just like is explained
    here.
    But when I try to create a new project the implemented workflow failed to start with the follow state message in the job queue: Failed But Not Blocking Correlation.
    The detailed error display the follow message:
    Exception Starting Workflow: The scope _/SharePoint/default/139e833f-7a85-4ccf-b7a2-b3fea9ce50b9/6799b7e5-e519-40f4-9371-0b3bc3d5c208_ has no workflows under it. HTTP headers received from the server - ActivityId: 52fef415-409b-4545-a9f6-ed75519b425c.
    NodeId: My-Computer-Name. Scope: /SharePoint/default/139e833f-7a85-4ccf-b7a2-b3fea9ce50b9/6799b7e5-e519-40f4-9371-0b3bc3d5c208. Client ActivityId : 9ded4d9c-7733-7004-2661-c8977270af98.. Trace:    at Microsoft.Workflow.Client.ClientHelpers.SendRequest[T](HttpWebRequest
    request, T content)   at Microsoft.Workflow.Client.WorkflowManager.StartInternal(String workflowName, WorkflowStartParameters startParameters)   at Microsoft.SharePoint.WorkflowServices.FabricWorkflowManagementClient.StartInstance(String
    serviceGroupName, String workflowName, String monitoringParam, String activationKey, IDictionary`2 payload)   at Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider.StartWorkflow(WorkflowSubscription subscription, IDictionary`2 payload)  
    at Microsoft.Office.Project.Server.BusinessLayer.Workflow.StartWorkflow(Guid projectGuid, Guid enterpriseProjectTypeUid, Boolean isNewProject, Guid previousEntepriseProjectTypeUid, Boolean skipStage, Guid stageToSkipTo):
    WorkflowExceptionStartingWorkflow (35115). Details: id='35115' name='WorkflowExceptionStartingWorkflow' uid='e3bbb06b-1d38-e311-940a-001cc094718e'.
    Error:
    WorkflowCannotStartWorkflow (35100). Details: id='35100' name='WorkflowCannotStartWorkflow' uid='e4bbb06b-1d38-e311-940a-001cc094718e'.
    Queue:
    GeneralQueueJobFailed (26000) - WorkflowStartWorkflow.WorkflowStartWorkflowMessage. Details: id='26000' name='GeneralQueueJobFailed' uid='e5bbb06b-1d38-e311-940a-001cc094718e' JobUID='68ee1040-1d38-e311-940a-001cc094718e'
    ComputerName='90f7432c-fbc8-4ebd-86f3-0236ce62661c' GroupType='WorkflowStartWorkflow' MessageType='WorkflowStartWorkflowMessage' MessageId='1' Stage='' CorrelationUID='9ded4d9c-7733-7004-2661-c8977270af98'. For more details, check the ULS logs on machine
    90f7432c-fbc8-4ebd-86f3-0236ce62661c for entries with JobUID
    68ee1040-1d38-e311-940a-001cc094718e.
    with this detailed entries in the log file
    10/18/2013 13:47:57.38  Microsoft.Office.Project.Server (0x0948) 0x14F0 Project Server                 Queue                        
     ad3fy Critical Standard Information:PSI Entry Point: <unknown>  Project User: <unknown>  Correlation Id: <unknown>  PWA Site URL:   SA Name: <unknown>  PSError: <unknown> A queue job
    has failed. This is a general error logged by the Project Server Queue everytime a job fails - for effective troubleshooting use this error message with other more specific error messages (if any), the Operations guide (which documents more details about queued
    jobs) and the trace log (which could provide more detailed context). More information about the failed job follows. GUID of the failed job: 68ee1040-1d38-e311-940a-001cc094718e. Name of the computer that processed this job: 90f7432c-fbc8-4ebd-86f3-0236ce62661c
    (to debug further, you need to look at the trace log from this computer). Failed job type: WorkflowStartWorkf... 9ded4d9c-7733-7004-2661-c8977270af98
    10/18/2013 13:47:57.38* Microsoft.Office.Project.Server (0x0948) 0x14F0 Project Server                 Queue                        
     ad3fy Critical ...low. Failed sub-job type: WorkflowStartWorkflowMessage. Failed sub-job ID: 1. Stage where sub-job failed:  (this is useful when one sub-job has more than one logical processing stages). 9ded4d9c-7733-7004-2661-c8977270af98
    10/18/2013 13:47:57.38  Microsoft.Office.Project.Server (0x0948) 0x14F0 Project Server                 Queue Jobs                   
     ad3fy Medium   Error is: GeneralQueueJobFailed. Details: Queue Attributes:  68ee1040-1d38-e311-940a-001cc094718e  90f7432c-fbc8-4ebd-86f3-0236ce62661c  WorkflowStartWorkflow  WorkflowStartWorkflowMessage  1   
    9ded4d9c-7733-7004-2661-c8977270af98  . Standard Information: , LogLevelManager Warning-ulsID:0x000DD158 has no entities explicitly specified. 9ded4d9c-7733-7004-2661-c8977270af98
    Any idea?
    Thanks in advance,
    Alexander.

    Hi Alexander,I have seen that error when the workflow manager has not been registered correctly with the PowerShell command - that should be in the docs referenced - or
    http://technet.microsoft.com/en-us/library/jj663115.aspx.  Let me know if that doesn't appear to be the issue here and I can dig deeper.  Best regards,  Brian
    Blog |
    Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter |
    Project Developer Center |
    Project Server Help | Project Product Page

  • HT201413 I have a Windows XP Home Edition computer.   I recently attempted to upgrade iTunes to v10.7.  It loaded and installed OK, but now it won't run.  When I try to launch it, it gets aborted by the windows Data Execution Prevention software.  Any ide

    I have a Windows XP Home Edition computer.   I recently attempted to upgrade iTunes to v10.7.  It loaded and installed OK, but now it won't run.  When I try to launch it, it gets aborted by the windows Data Execution Prevention software.  Any ideas?

    Yes, this did solve the problem.  But I had some trouble updating QuickTime.  It failed, with the installer complaining that it did not have the required permissions to install the files it needed in the program directory.  I got it to work by telling it to install the files to another directory.  All seems well now - Thanks!

  • Photosmart C6180 on wireless network does not respond when attempting to print

    Photosmart C6180 successfully installed on wireless network does not respond when attempting to print.  All in one is successfully installed on wireless network and SW successfully installed on Windows XP computer yet printer does not print.  Get no error message other than document failed to print.  HELP!

    So gald I'm not the only one. I have been fighting this crappy HP printer for MONTHS also. Everything says a OK goody goody but printer fails to print every two to three weeks.

  • Software Restriction Policy not blocking MSI files

    Hello, we have one SRP in place on our domain that includes MSI files in the Designated File Types, however it is not blocking users from running them.  Has any one else had this issue?  What are some things I should look out for?  Thanks.

    Hi Erin,
    >>we have one SRP in place on our domain that includes MSI files in the Designated File Types, however it is not blocking users from running them.
    Are these users standard user accounts (without administrative privileges) ? Besides, what SRP rule did we configure to disallow the .msi files? Here, we can run command
    gpreport.html gpresult/h to collect  group policy result report to check how group policy settings are applied. Note, to collect computer part group policy setting report, we need to run the command with administrative privileges.
    In addition, to block .msi files, we can also use Applocker to do this. Regarding Applocker, the following article can be referred to for more information.
    AppLocker Overview
    https://technet.microsoft.com/en-us/library/hh831440.aspx
    Understanding AppLocker Rules
    https://technet.microsoft.com/en-us/library/dd759068.aspx
    Best regards,
    Frank Shen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Blocksite does not block a bookmarked site

    I installed Blocksite to use it to block Facebook on my home computer. It works if I type in the URL in the text box. But, if I click on the bookmark on the toolbar for Facebook that was saved before I downloaded Blocksite, it does not block Facebook. Any suggestions?

    [http://support.mozilla.org/en-US/kb/Firefox%20cannot%20load%20websites%20but%20other%20programs%20can#w_firefox-cannot-load-certain-websites Firefox cannot load certain websites]
    thank you

Maybe you are looking for

  • Does Endeca Integrator Loads Attribute with Null value?

    I have a table in DB , with a column , lets say, supply_id. This is null for all rows. When i load data from this table using clover ETL graph and lets say source this data to another table , will my final table will have a column as supply_id? Or wi

  • Select statement takes very long

    Hello from Germany, how comes that from one week to another my select-statement "select MAX(PRIMARYKEY) from mytable t where t.IntegerColumn = 5" takes 20times longer (25s) than before (0,4s)? The RowCount of myTable is 89899. Best Regards Marlon

  • Change fields

    Hi Pls let me  know how to make the profit center field in the cost center master data and the segment field in the profit center master data mandatory?? Tks

  • Loading Historical data to the new field without deleting the data in cube

    Dear BI Experts, I have enhanced a new field to the Generic data source in BI 7.0 . I need to load historical data to the newly  appended field. As we are having very huge data it is not possible to delete and do init again. Is there any  other possi

  • How to Repeat Playlist from Music

    From Ipod touch and classic, there's setting to make playlist repeat. I can't find it from Ipod nano 6th generation. How can I make playlist repeat? Message was edited by: youngnapoli