Computer Wins Every Time At Connect 4 Game

May 9, 2015

I have to make my connect 4 game smarter with an algorithm that can beat the human every time. How to do it??

View Replies


ADVERTISEMENT

Tic Tac Toe Game - GUI Freezes When Someone Wins

Jan 16, 2015

This code is for a tic tac toe game. I have a action listener set up and if the user entered a move that would win the game of tic tac toe it would call on a restart() method to clear the board, but every time some one wins the GUI freezes.

class ListenerCA implements ActionListener {
public void actionPerformed(ActionEvent event) {
Board.clear();
if (turn == 0) {
start.answer = "CA";

[Code] .....

The code below this is the normal execution flow.

static void start_game(String board[][]){
final int one = 1;
final int two = 2;
int x = 0;
play game = new play();

[Code] .....

In the above code gui == true always, I just kept an option if i ever wanted to run the program in console. The code below is the restart method.

static void restartgui() {
gui = true;
if (gui ==true) {
board[0][0] = " ";
board[0][2] = " ";

[Code] ....

View Replies View Related

Getting TIE In Connect 4 Game?

Oct 20, 2014

I have compiled and coded the whole thing, but the TIE function when no one wins, isn't popping up. I'm not sure why but here is my code;

import java.applet.AudioClip;
import java.awt.*;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;

[code]....

The TIE doesn't pop up, that is all the errors i have, though there is no error messages.

View Replies View Related

Connect Four Game

Nov 25, 2014

Our assignment is to make a version of the classic 'Connect Four' game, where we need to construct a GUI that shows the current state of the game and instead of having a winner once a player has four chips in a row, the game needs to continue until no chips can be placed anymore.We currently get stuck in the GUI part. Running it right now results in a board with empty spaces only. Also after choosing a column to place, the board remains empty.

Our question: How do we get the board filled with the right color of chips at the right place?We know the 'ArcsPanel'-class (almost at the bottom of the code) is wrong, but we don't know what to do to make it right.

Main class 'ConnectPanel':

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;

[code]....

At the moment, only the colors white, red and blue are used. This is purely for finding out how to work in general.

View Replies View Related

Making Counter AI For Connect 4 Game?

Apr 28, 2015

I am a student in an intro to computer science class working on my final project. This is essentially a game of connect 4, but only requiring 3-in-a-row for victory. We were given the base game and a sample file to work with to make an AI that beats our professor's ai in the base game. Here is the base game

package cs110.project3;
 import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

[code].....

View Replies View Related

Make A Connect 4 Game With Java

Nov 17, 2014

I have to make the connect 4 game be connect 3. Ive edited a code but I the math is over my head. These loop methods check the ways someone can win.

for (int j=0;j<7;j+=2)//need to change
{
if ((f[i][j+1] != " ")
&& (f[i][j+3] != " ")
&& (f[i][j+5] != " ")
&& (f[i][j+7] != " ")
&& ((f[i][j+1] == f[i][j+3])
&& (f[i][j+3] == f[i][j+5])
&& (f[i][j+5] == f[i][j+7])))
//end of loop

[code]....

View Replies View Related

Connect Four Game With Java Swing / Make Multi D Panel Maker When Try To Run It

May 31, 2014

I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.

import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
[code]...

View Replies View Related

Game Combat / Fighting One Enemy At A Time?

Mar 1, 2014

So I'm making a combat system for a game I'm working on.The combat is basically like old-school Runescape's, where the 2 participating combatants take turns hitting each other.Except, in this game, I'm trying to make it so you can only fight one enemy at a time, no matter what. I'm trying to make so if you're fighting a mob and you try to attack another, your action is ignored and you continue your current fight.

I'd post the code I have, but it is such a mess with all the booleans and other variables being in other classes that I'd have to post the whole project itself.

Here's the sequence I have:

1. I try to fight an enemy. (Once I'm in their "fight radius" and press space)

2. They fight me back. (Executes their combat-style method, in this case, non-hostile)

3. I walk away and try to fight another enemy. (I'm still in the other enemy's "chase radius" and they follow me as I try to attack another enemy)

4. I'm able to fight the other enemy, resulting in a 1 vs 2 fight. (The second enemy executes the same non-hostile combat method to fight back)

I don't want that. This is my goal:

1. I try to fight an enemy. (Once I'm in their "fight radius" and press space)

2. They fight me back. (Executes their combat-style method, in this case, non-hostile)

3. I walk away and try to fight another enemy. (I'm still in the other enemy's "chase radius" and they follow me as I try to attack another enemy)

4. I'm unable to start another fight because I'm already fighting a different mob. (The second enemy just ignores as the enemy I attacked first walks up to me and continues to attack until I kill it or run away)

Is this because of static/non-static methods and values? Instances?

I tried everything but I cannot get this 1-enemy-per-fight limit to work.

View Replies View Related

Counting Wins And Losses From RPSLS Method

Apr 26, 2015

Okay, so this is the program I've written thus far. The biggest issue I'm having is counting the wins and losses from the rpsls method. I know that the line

int output = rpsls(retVal);

isn't valid, but can't figure out a way to call the retVal from rpsls in. I've been at this all day and still can't make it work.

import java.util.Scanner;
public class Rpsls
{
public static void main (String [] args) {
//while loop
Scanner input = new Scanner (System.in);
int x = input.nextInt();
while (x > 0 && x <= 5)

[Code] .....

View Replies View Related

Java 2D Game - Overcoming Max Of Three Keys At A Time Limitation Of Keyboard

Jan 7, 2014

I'm working on a Java 2D game which requires a max of six keys be held down at the same time.

The game is for two players on the same keyboard, playing simultaneously.

However, all three computers I ran the program on only allow a max of three keys held at a time. They all have trouble with reacting to more than three keys being held.

It seems that pressing a new key after three are already held, either cancels some other key-holding or is ignored.

I've been told that this is a hardware issue. Most keyboards can't handle more than three keys held at a time. But a lot of games do require this, and they do not require special gaming-keyboards to run on my computer without problems.

So there has to be a solution that will make the game playable on any standard keyboard.

(I use Key Bindings).

The game's controls:

Player 1

- Rotate sprite and set angle of movement: LEFT arrow

- Rotate sprite and set angle of movement: RIGHT arrow

- Move forward: UP arrow

- Shoot missile: ENTER key

Player 2

- Rotate sprite and set angle of movement: 'A' key

- Rotate sprite and set angle of movement: 'D' key

- Move forward: 'W' key

- Shoot missile: 'T' key

Relevant code:

The Key Bindings part:

Java Code:

// An action for every key-press.
// Each action sets a flag indicating the key is pressed.
leftAction = new AbstractAction(){
public void actionPerformed(ActionEvent e){
keysPressed1[0] = true;

[Code] .....

This is mostly how reacting to key-presses and key-releases works in my program. When a key is pressed or released, a flag is set. The Board class reades the flags every game-loop cycle and reacts accordingly.

As I said, the program doesn't react correctly to more than 3 keys held at a time, probably because of the keyboard. Is there a way to code a solution?

View Replies View Related

How To Code MMO Real-time Strategy Social Game In Java

Aug 25, 2014

I want to work on a project related to MMO real-time strategy social game as a college project but i dont have enough knowledge on it starting from 3d object coding to server.

Also i would like to know what are things to be cosidered as its an online game whether the camera angel affect what are problems that might occur and how to outrun it. How to split the server so that in one server depending upon the geo-location some number of users will be connected and will be splitted in different servers depending on the location

I want the actions to be cloud based but the actions of the characters will be coded within the game and in every server maximum of 100 users can connect.

Create several rooms.

View Replies View Related

Guess Picture Game - How To Sort Picture Random Every Time

May 3, 2014

I will write guess the picture game. I didn't find for example 4*4 picture how to sort picture random everytime ?

For example , when game start random various are 2734856127348561 two times same picture...

View Replies View Related

Get Computer CPU Usage?

Apr 7, 2014

I want to get current Computer CPU usage of my computer and display it in Console View of Eclipse? How can I achieve this?

My template code is:

Java Code: public class GetCPUUsage{
public static void main(String[] args){
System.out.println("CPU USAGE IS: ??????");
}
} mh_sh_highlight_all('java');

I added ??? as placeholder for CPU usage because I do not know how to retrieve RAM usage by Java.

View Replies View Related

How To Get The Actual Computer IP Address

Jan 31, 2014

I wrote a Chess game that uses socket to connect to another computer, and allow player vs player and player vs computer game sessions.

However, there is a problem which I noticed.

When you get the IP address of the computer in which the program is running, you are not getting the computer's actual IP, you are getting the Router's IP.

Is there a way to get around this.

So the problem is that when I go to another computer, located in a different house or lets say from my school, the program cannot connect back to my home IP, because it uses the router's ip, not the computer's ip I am running the server program.

Is there a way to get the Computer's IP, not the router's ip when summoning or invoking the get IP address method from the socket class?

When I say that the socket class is acquiring the router's ip, well that's done without my interfering...I don't know why it does that, it is somehow recognizing the router and not the computer.

The thing is that the server program is written that any client program is able to connect to the home server.

But when I run the program from a different location other than the current home, the sockets don't connect because it is somehow recognizing the router's ip not the computer's ip.

View Replies View Related

How Java Graphics Interact With The Computer

Mar 30, 2014

I know there are Java graphics classes, and how to use them to draw images in a window, but how do those classes interact with the screen to create the image? At the very base of it all, what is the code that is passing the computer the data to display on its screen? I'm asking because I've seen several ways to do Graphics/GUIS, a lot of them involve the Graphics class, but what is it inside all of that that that makes it work? Also, is everything else involving graphics (any other graphics libraries people write) pretty much "on top" of the Graphics class or is there something else within it more basic that is being used?

View Replies View Related

Display What The Computer Chose (GUI Boxes)

Nov 29, 2014

for my class we have to make a rock paper scissors game using GUI boxes. Everything is working fine I'm just having trouble displaying what the computer chose. In other words, after the user selects Rock, paper or scissors, the scoreboard just pops up displaying the score. Here's the last working program before I started tinkering with it.

// your code goes here
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;

[Code].....

View Replies View Related

Communication Between Two Separate Java Program In Same Computer

Sep 20, 2012

I have two separate java Program that run on the same
computer : Program -1 & Program-2 .

Explain Program-1 :

Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .

Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .

This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .

I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .

View Replies View Related

Pogo Games - Java Is Not Detected On Computer

Jun 6, 2013

I am unable to open Pogo Poker with out receiving an error message saying "Oops, Java is not detected on your computer" (or something similar). I have reinstalled it several times and get the same results.

View Replies View Related

How To Write A Computer Based Testing Program Using Files

Jan 8, 2015

I'm supposed to write a computer based testing program using files. I have started writing however, I am stuck. I am to prompt the user to enter the file name 'test.dat" and if something different is entered then a error message should be displayed. Also the file will create an input stream for the data using the file. I am to have the user enter other information about an employee and then write the record to the file.

The program should be created so when the user enters "quit" the loop is terminated and the file is closed. I'm not asking for code. I was just giving a brief synopsis of the project. Where I am stuck is I wrote the first part of the program that creates the file; however when I enter a wrong file name the exception error message does not display. The code is below:

import java.io.*;
import java.lang.*;
import java.util.*;
public class Project5Write
{
private Formatter x;
public void openFile(){

[Code]...

View Replies View Related

JRE :: Keep Temporary Files On My Computer Via Command Line On Windows

May 18, 2015

I need to activate the setting 'Keep temporary files on my computer' (Java control panel/general/settings) on about 150 Windows 7 PCs in a Samba3-Environment (which does not have GPOs). We are running Java Version 8 Update 45 (build 1.8.0_45-b14) on all of the PCs. Is there a way to change this setting with the command line, a registry entry or somehow else?

View Replies View Related

Get Current RAM Usage Of Computer And Display It In Console View Of Eclipse?

Apr 7, 2014

I want to get current RAM usage of my computer and display it in Console View of Eclipse? How can I achieve this?

View Replies View Related

Swing/AWT/SWT :: Procedure For Detecting A Unique Hardware ID Of Any Computer Using Java

Apr 8, 2014

I need to know the procedure for detecting a Unique Hardware ID of any computer using Java. All I want to do is once the software application is installed should not get installed using the same key...In short I want to do license for my application.

View Replies View Related

Military Time - Adding Minutes Displaying Correct Time

Feb 9, 2015

I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)

I need the output time to be the time the class started, plus the length of the class, and displayed in military time.

for example,

Start Time = 0930
Length = 50 minutes
Endtime = 1020

I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say

Start time: 0700
Length = 90 minutes

I get:

Endtime = 90

90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.

Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.

public class calc
{
public static void main(String[] args) {
double hours, minutes, length;
double temp;
int time = 2400;
hours = time / 100;
System.out.println("Hours are: " + hours);

[Code] ....

View Replies View Related

Comparing Inputted Guess To Computer Random Sequence - Counter Not Working?

May 27, 2014

I have separated characters into an array that can be accessed from any method, however, when I try to compare the inputed guess to the computers random sequence, the counter always comes back as 0 (the comparison occurs in the checkColour method).

Java Code:

package mastermind;
import java.util.Scanner;
/**
* Program Description: play a game of mastermind versus the computer
*/
public class Mastermind {
private static int block1, block2, block3;
private static String blockColour1, blockColour2, blockColour3;

[Code] ....

The counter is called colourCorrect.. But I think the problem lies more in me converting the strings (input and computerGuess) into char arrays, as if I output the values at position in the array, I get numbers (but the numbers are not character values from the ascii table).

View Replies View Related

Converting Military Time To Standard Time?

Jan 29, 2014

I have two classes. time_runner is used for testing my code.

This is what I'm using to test my code:
 
class time_runner
{
 public static void main(String str[]) throws IOException {
 Time time1 = new Time(14, 56);
System.out.println("time1: " + time1);
System.out.println("convert time1 to standard time: " + time1.convert());
System.out.println("time1: " + time1);
System.out.print("increment time1 five times: ");
time1.increment();

[code]....

The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.

public class Time {
private int hour;
private int minute;
  public Time(int h, int m) {
if(h > 1 && h < 23)
hour = h;

[code]....

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved