Checker Game With Minimax Algorithm
Apr 12, 2015I have a checker game already and I am trying to make an AI opponent even if not so Intelligent as long as it can move chips on its own until the game is over.
View RepliesI have a checker game already and I am trying to make an AI opponent even if not so Intelligent as long as it can move chips on its own until the game is over.
View RepliesI have been trying to create an algorithm for the computer in my Tic-Tac-Toe game? So I searched for some good ones, and found about this confusing but effective algorithm, at least if you get it working, called Minimax. I tried implementing it into my game. Let's say it was easier said than done. Sometimes I think it's working, but sometimes it doesn't work at all. How do I get my algorithm working? What the variables BEST_SCORE_COMPUTER and BEST_SCORE_PLAYER in my code should have as starting values.
Java Code:
import java.util.Scanner;
public class TicTacToe{
private static char BOARD[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; // This is the main board itself.
private static int ROWS[][] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}}; // These are all the rows one can win by filling.
private static int SCORE, BEST_MOVE_COMPUTER, BEST_SCORE_COMPUTER = -1, BEST_SCORE_PLAYER = 1; // These variables speak for themselves.
private static byte TURN = 1; // 1 means player's turn, and 2 means computer's turn.
[Code] .....
I'm trying to make a checkers game in Java and I managed to make my grid with it's button on it. Each button which has a pawn on it has it's own actionListener which was all done in the loop as I made the grid as shown in my code below. Now I have a huge problem. I don't know how to handle the move, check if move is legal, jump and double jump. Here is the code I wrote so far. I wrote it in such a way that all the buttons which have a pawn on them can perform the same action but then I'm completely stuck.
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class CheckerBoard extends JPanel{
public static final int WIDTH = 530;
public static final int HEIGHT = 530;
private JButton[][] grids;
[Code] .....
I am working on replicating this project: [URL] ....
What is wrong with the moveSnake method and the for loop within it?
I am making an android racing game. I have a method that draws the track to the screen, the map is bigger than the screen so i clip the bitmap and draw it to the screen hence to draw the track I have to get the visible track points and then draw them. I have noticed that when I enable drawing the track the game lags quite a bit but when i disable it is smooth as expected the code is below :
public void drawTrack(Canvas canvas) {
if (this.trackPoints != null && this.trackPoints.size() > 0) {
// get points, convert back to screen coords and add them to array,
// then
// use that arraylist<point> below
getCurrentVisibleTrack();
counter++;
if (this.visibleTrackPoints.size() > 0) {
[Code] .....
It had no syntax error but if there would be any other error or if i would receive a wrong result
import java.util.*;
class tester {
public static void test() {
Scanner input=new Scanner(System.in);
int size= 0;
System.out.println("Enter your password:");
String enter=input.next();
size = enter.length();
[Code] .....
i have this source code...
import java.util.Scanner;
//I had to use scanner in this program because I had to create objects that were in the Scanner class, such as in row 16.
* This program confirms a password typed into a *
* console window *
*/
public class Homework1 {
public static void main(String[] args) {
//Needs to add a scanner to the program to continue on
Scanner keyboard = new Scanner(System.in);
[code]....
Now I need to create a second version of this program that uses JOptionPane to get the inputs from the user and show the output!
Use Java to write and run a simple console-window program for checking passwords. The program must satisfy the following requirements:
-When the program runs, it should first print its name, e.g., Password Checker
-The program should next prompt the user to enter a username, e.g.,
Please enter your username:
-The program should next prompt the user to enter a password, e.g., Please enter your password:
- If the user enters a correct password, i.e., one that matches an internal secret password, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
Try again:
-If the user enters a correct password matching the secret one, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
package class1;
import java.util.Scanner;
public class class1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
[code]....
I am trying to write a password checker program and thats the error i get. (the final error!) but this one i dont know how to fix. here is my code.
/* Text
Text
text
*/
import java.util.Scanner; // Imports the Scanner class to get Keyboard Inputs
class PriceRichardChapter5Test
{
public static void main (String [] args) {
String Password; // Creates the Password variable
[Code] .....
I am trying to use this program for reference but its not working ...
View Replies View RelatedI can't get the code to compile for the driver every time i get an error message saying
SudokuCheckerTest.java:28: error: cannot find symbol
foo.displayGrid(grid);
^
symbol: variable grid
location: class SudokuCheckerTest
SudokuCheckerTest.java:29: error: cannot find symbol
foo.getGrid(grid);
[Code] .....
4 errors
Java Code :
import java.util.Scanner;
public class SudokuChecker{
public SudokuChecker(){
// displays intro code and initializes the array grid as well as using method calls.
Scanner in = new Scanner(System.in);
int [][] grid = new int [4][4];
displayGrid(grid);
[Code] ....
Iv created an array list which contains people and attributes such as user id, username etc. It works fine for the most part. It allows the user to enter a name into the system. If the name entered matches a name stored in the array list then it will display that user, its id, name and password. I need to implement a password strength checker; but i am struggling.
First off; i need a method that will determine how strong a password is. I then need to find a means of how to output the result of this, outputting it alongside the other outputted attributes: id, name and password.
Here is what i have attempted so far, but to be honest its probably completely different to the exact strength check and way that i want the result to be displayed. I know that the code below is a good start, but its not close to implementing the code in a way that the password strength result can be outputted in the arraylist after a search for a user and their password is made.
private int checkPasswordStrength2(String passw)
{
int strengthCount=0;
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%]+.*" // symbols
};
if (passw.matches(partialRegexChecks[0])) {
[Code] .....
I just really want to get this done. Iv looked for solutions online; but they implement a password strength checker much differently to how mine needs to work from what i can tell.
Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.
In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.
Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:
**o******
means that the player is at location 2 on the board.
Here are the other Opoly game rules:
If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).
If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,
Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.
Here is the driver class for the game:
import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();
[Code] ....
heres the methods:
REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:
playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.
spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.
spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.
move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.
isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.
drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.
displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.
Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.
import java.util.Random;
import java.util.Scanner;
public class TicTacToe {
private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
[Code] ....
I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).
*I have included a zip file with:
-base program
-driver program
-data file
-key data file
I have a code that is meant to read a file and organize all the names from least to greatest salaries. It also allows the user to enter a name to find from the file, and the program finds the name and displays it. I have two errors, and I will show the error in my code
View Replies View RelatedI'm making a code for a log in system that allow me to verify if username and psw are correct (using a file txt as refer), and then i will add maybe the possibility to sign up.
The fact is that I want this kind of formatting on the .txt
username psw
username psw
username psw
...etc
So I have to read the lines and split to the " " and compare the insert data and the read data.
Here is my code, it star but give me this error when i insert any word
XML Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at prova.main(prova.java:20) mh_sh_highlight_all('xml'); Java Code: import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class prova {
public static void main(String[] args) throws FileNotFoundException {
[Code] .....
What is difference between algorithm and programming?How to develope algorithm knowledge?
View Replies View RelatedEncryptor
Java Code:
Private Sub cmdDeleteMessage_Click()
If txtMessage.Text = "" Then
a = MsgBox("No message to delete!", vbInformation, "")
Else: If MsgBox("Do you want to create a new message?", vbYesNo, "New") = vbNo Then Exit Sub
txtMessage.Text = ""
Pic.Picture = LoadPicture()
[Code] .....
Is these codes of the Block cipher encryptor for text-to-image algorithm (B-TTIE algorithm) by Abusukhon 2013? If not, how to make it the same with B-TTIE algorithm?
how to create a genetic algorithm.I made this class that Is supposed to Generate the chromes or Possible solutions of the program. Im pretty sure It doesn't have any syntax error and I went over the logic a couple time yet Im getting a NumberFormatException Exception Error. What this error means nor why am I getting it. Here's my code:
/* Contains the genes or possible solutions to the problem
*/
public class Genes
{
/* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes
* The last 4 elements in the array represent + - * / correspondingly
*/
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};
[code]...
I have a set of numbers within a text file.
2 6
1 4 4 1
When the program reads these numbers it will start with the first line. It reads 2, this is the number of times the program should loop through the numbers of the second line. Next it reads 6, this is the number that the sum of numbers on line 2 cannot go beyond, it must equal 6 or be less than.
Next it goes to line 2 and processes the numbers, 2 is less than 6 so it gets processed, so is 4 and when added to 2 it equals 6. This passes the rules therefore gets processed and added together and put in a variable. Once 2 and 4 has been processed it gets put at the back of the number queue, so the numbers look like 1 1 2 4.
With one loop done there is only one left, so it processes the next sum of numbers 1 1 2 as these equal 4 and pass the rule. So these get added together and and put to the back of the queue, 4 1 1 2. But all the loops are finished and the sum of the last loop is added on to the sum of the previous loop. 6 + 4 = 10.
What I need the algorithm to do is print the sum of this whole process when it reads these numbers from a file. I am able to read the numbers from a text file but not sure where to proceed from there.
Also the set of numbers vary, for example the next 2 lines of numbers could be,
10 7
3 1 1 1 4 4
Is it possible to enable & disable "jdk.certpath.disabledAlgorithms" property programmatically. I want to remove all disabled Algorithms for some time and later I will enable it.
Or is it possible to enable only for a particular place & not in a JVM level. I want that Algorithm need to be enabled for a piece of code, but I don't want it to the remaining part of the application.
I am looking to program a simple genetic algorithm in Java but where to start.
" In a computer language of your choice, implement a simple genetic algorithm (GA). That is, write code for a generational GA which uses a binary encoding, tournament selection, single-point crossover and bit-wise mutation" ....
I have been given this Pseudocode for the Quicksort algorithm:
quicksort(a[], p, r)
if r>p then
j=partition(a[], p, r)
quicksort(a[], p, j-1)
quicksort(a[], j+1, r)
[code]....
I was wondering why:
- why the condition left < right needs to be true for the while loop in the function Partition
- what the while loop does in the function Partition
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main(String args[])
{
String choice="y";
[Code] ......
I am using what is known as a Depth First Search to solve a maze using my own Stack created class for an assignment. The reason I believe I am getting this error is because my program is never meeting the `finishSpot` condition. I have used the debugger and it looks like it is infinitely stuck at the Point before the `finishSpot`. My logic seems to be mostly correct except until the point where my maze solver tries to finish the maze.
This is a sample maze:
*****
*s* *
* * *
* f*
*****
Here is my Main which uses my created Stack class.
//Creates a Stack and determines the start and endpoints.
public static void solveDFS( char [][] maze ){
LinkedStack stack = new LinkedStack();
Point currentSpot = findPoint( maze,'s' );
Point finishSpot = findPoint( maze, 'f' );
findPath( maze,currentSpot, finishSpot,stack );
[code]....