zim1985's Profile User Rating: -----

Reputation: 74 Whiz
Group:
Contributors
Active Posts:
569 (0.34 per day)
Joined:
19-February 10
Profile Views:
9,885
Last Active:
User is offline May 23 2014 03:15 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Honda
Dream Kudos:
50

Latest Visitors

Icon   zim1985 has set his status

Posts I've Made

  1. In Topic: Trying to Add Multiple Levels of AI to Game - Not Sure Where to Start

    Posted 22 May 2014

    Actually I'm not looking to increase the size of the grid. I am looking to have different levels of computer difficulty.

    That said, I'm sure some of what you've posted will be helpful and I'll make sure to look through it when I get a chance later today.

    View Postmodi123_1, on 21 May 2014 - 09:26 AM, said:

    Explain how your AI currently decides where to move.

    A few questions.

    Why five levels?
    Have you given much thought on what should differentiate the AI between levels? Depth of branching simulations on moves? Mistakes made? Randomness introduced?

    Well 5 levels so you can play different difficulty of computer.

    Level 1 - Easy: Computer will just pick a random unoccupied tile.
    Level 2 - Medium: Computer recognizes when a player has a winning move and will attempt to block them from winning.
    Level 3 - Hard: Computer will try and take winning moves.
    Level 4 - Very Hard: Computer will value corners and center tiles over sides. Will only take sides to win/block.
    Level 5 - Impossible to beat the computer.

    I realize some of these levels will build off of one another. Like Level 2 is just Level 2 except with the Player win condition recognition and Level 3 is just like Level 2 except with computer win condition recognition. Level 4 and 5 are the ones I'm pretty much stumped on logically. I have no idea where to really start for any other these aside from the Level 1 (though I have implemented some code it does not work correctly).
  2. In Topic: Tic Tac Toe

    Posted 15 May 2014

    View PostCurtis Rutland, on 15 May 2014 - 10:26 AM, said:

    First suggestions: set a breakpoint in the areas you suspect aren't working. Trace the execution line-by-line using the debugger to see how your logic actually flows, and to inspect values on the fly. That should grant you some insight into the problem.

    Now the part I'm confused about is this:

    Quote

    he section of code to deal with a draw does not trigger


    Does this mean that you suspect the code isn't doing what it's supposed to, or that it's never actually being called?


    I suspect that my code is never being called. Even though the criteria for a draw arises, I don't think that else-if block is ever actually being executed and I'm not sure why because I look at my logic and it makes sense to me.
  3. In Topic: Simple Game with Computer Turns

    Posted 2 May 2014

    If anyone is interested...I updated my code with some suggestions but now I'm just getting a weird loop effect that I'm having a hard time placing. I really need some help. Not a lot, just enough to get me going. Please. This problem is driving me crazy.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.VisualBasic;
    
    namespace DiceGame
    {
        public partial class Form1 : Form
        {
            private int numRolls = 0; //number of rolls in a turn
            private int turnScoreVal = 0; //total score for a turn
            private int roll = 0; //roll value
            private int p1ScoreVal = 0; //player 1 total score
            private int p2ScoreVal = 0; //player 2 total score
            private int turn = 1; //turn counter :: odd = player 1, even = player 2
            private int numPlayers = 0; //number of players
    
            private System.Timers.Timer t = new System.Timers.Timer();
    
            private void reset()
            {
                numRolls = 0; //reset turn roll counter
                roll = 0; //reset roll
                turnScoreVal = 0; //reset turn score
                turnRolls.Text = "0"; //reset turn fields
                rollVal.Text = "0";
                turnScore.Text = "0";
    
                if (turn%2==0) currentPlayer.Text = player2.Text; //switch players :: even turns are player 2
                else currentPlayer.Text = player1.Text; //switch players :: odd turns are player 1
            }
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void rollButton_Click(object sender, EventArgs e)
            {
                numRolls++; //count how many dice rolls in a turn
                turnRolls.Text = "" + numRolls; //update number of rolls
                standButton.Enabled = true; //enable stand button
                Random r = new Random(Environment.TickCount);
                roll = r.Next(1, 6); //create value for roll
                rollVal.Text = "" + roll; //display roll
                if (roll == 1) //turn over if roll is a one
                {
                    MessageBox.Show("Rolled a 1.  Turn over.");
                    turn++;
                    reset();
                    standButton.Enabled = false; //disable until roll button is pressed again
                    return;
                }
                turnScoreVal += roll; //total the turn rolls
                turnScore.Text = "" + turnScoreVal; //display total turn score
            }
    
            private void standButton_Click(object sender, EventArgs e)
            {
                if (currentPlayer.Text == player1.Text) //update player 1 score
                {
                    p1ScoreVal += turnScoreVal;
                    p1Score.Text = "" + p1ScoreVal;
                }
                else //update player 2 score
                {
                    p2ScoreVal += turnScoreVal;
                    p2Score.Text = "" + p2ScoreVal;
                }
                if (p1ScoreVal >= 100) MessageBox.Show(player1.Text + " wins!"); //win conditions
                if (p2ScoreVal >= 100) MessageBox.Show(player2.Text + " wins!");
                turn++; //next player's turn
                reset(); //reset turn field and change turn
                standButton.Enabled = false; //disable until roll button is pressed again
                if (turn % 2 == 0 && numPlayers == 1)
                {
                    t.Enabled = true;
                    t.Interval = 2000;
                    do
                    {
                        t.Start();
                        rollButton.PerformClick();
                    } while (turnScoreVal < 20 && roll != 1);
                        
                    t.Stop();
                    standButton.PerformClick();
                }
            }
    
            private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
            {
                p1ScoreVal = 0; //reset player 1 score
                p1Score.Text = "0"; //display reset score
                p2ScoreVal = 0; //reset player 2 score
                p2Score.Text = "0"; //display reset score
                turn = 1; //reset to player 1
                reset(); //reset turn field and change turn
            }
    
            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                this.Close(); //close game
            }
    
            private void setPlayer1NameToolStripMenuItem_Click(object sender, EventArgs e)
            {
                player1.Text = Interaction.InputBox("Player 1 Name", "Change Name", "", 0, 0); //popup to input a name
                if (turn%2!=0) currentPlayer.Text = player1.Text; //test if current player name needs to be updated
            }
    
            private void setPlayer2NameToolStripMenuItem_Click(object sender, EventArgs e)
            {
                player2.Text = Interaction.InputBox("Player 2 Name", "Change Name", "", 0, 0); //popup to input a name
                if (turn%2==0) currentPlayer.Text = player2.Text; //test if current player needs to be updated
            }
    
            private void setNumberPlayersToolStripMenuItem_Click(object sender, EventArgs e)
            {
                do
                {
                    numPlayers = int.Parse(Interaction.InputBox("Number of Players", "Number of Players", "", 0, 0)); //prompt for player number
                } while (numPlayers != 1 && numPlayers != 2); //keep prompting for players until a valid number is entered
    
                if (numPlayers == 1) player2.Text = "Computer"; //set second player to computer if only one player
            }
        }
    }
    
    


    Specifically I added this part to the code:
    if (turn % 2 == 0 && numPlayers == 1)
                {
                    t.Enabled = true;
                    t.Interval = 2000;
                    do
                    {
                        t.Start();
                        rollButton.PerformClick();
                    } while (turnScoreVal < 20 && roll != 1);
                        
                    t.Stop();
                    standButton.PerformClick();
                }
    
    


    I know it sounds like I'm begging but I really am. I've been trying to fix this for the last 2 hours non stop and it just isn't clicking...
  4. In Topic: Simple Game with Computer Turns

    Posted 2 May 2014

    So I tried implementing a Timer. Not really sure why the program is acting the way it is now...

    private void cpuTurn()
            {
                t.Enabled = true;
                t.Interval = 15000;
                while (turnScoreVal < 20)
                {
                    t.Start();
                    playerTurn();
                }
                t.Stop();
                standButton.PerformClick();
            }
    
    


    I really could use some help figuring out why the computer isn't working the way it should be. I'm not sure if I'm calling the function in the wrong place or what I'm doing wrong logically...
  5. In Topic: Simple Game with Computer Turns

    Posted 2 May 2014

    View PostCurtis Rutland, on 02 May 2014 - 09:52 AM, said:

    Just throwing another thing out there: there's basically no reason to use Thread.Sleep on a GUI thread, pretty much ever. Remember that if you're on your GUI thread, sleeping that thread means that nothing can be done. No updating the UI, no processing, even your UI will freeze.

    If you need to wait for a particular amount of time, you should use a Timer. There's several kinds of Timers, choose the one most appropriate to your program (resolution, threading, etc...)

    Hm that makes sense. I'll look into that. Thank you.

My Information

Member Title:
Grand Inquisitor
Age:
21 years old
Birthday:
July 22, 1993
Gender:
Location:
California
Interests:
-Programming
-Video Games
-Music
Full Name:
Mike Zrimsek
Years Programming:
5
Programming Languages:
Java, C, C++, Python

Contact Information

E-mail:
Private
Skype:
Skype  mzrimsek

Comments

zim1985 has no profile comments yet. Why not say hello?