作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试用Java初始化Othello的游戏板。它应该提示用户输入两个播放器名称,将播放器1设置为暗色,将播放器2设置为亮色,但是当我尝试编译时,出现以下错误:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: core.Disc.setColor
at core.Board.initObjects(Board.java:44) "board[3][3].setColor(Constants.LIGHT);"
at core.Board.<init>(Board.java:24) "initObjects();"
at core.Game.initObjects(Game.java:30) "board = new Board();"
at core.Game.<init>(Game.java:25) "initObjects();"
at othello.Othello.main(Othello.java:17) "Game game = new Game();"
package core;
// board class
public class Board {
// member variable board (always make access modifier 'private'
// Disc = data type (class)
private Disc[][] board;
// constructor (same name as class)
public Board(){
// method call for initObjects
initObjects();
}
private void initObjects(){
// declaring size of array // new is used to allocate memory
board = new Disc[Constants.ROWS][Constants.COLUMNS];
// looping and initializing board
for(int row = 0; row < Constants.ROWS; row++){
for (int col = 0; col < Constants.COLUMNS; col++){
// calling no argument constructor
// for class Disc
board[row][col] = new Disc();
}
}
// setColor is part of class Disc
board[3][3].setColor(Constants.LIGHT);
board[3][4].setColor(Constants.DARK);
board[4][3].setColor(Constants.DARK);
board[4][4].setColor(Constants.LIGHT);
}
/**
* @return the board
*/
public Disc[][] getBoard() {
return board;
}
/**
* @param board the board to set
*/
public void setBoard(Disc[][] board) {
this.board = board;
}
}
package core;
import java.awt.Color;
public class Constants {
public static Color DARK = Color.BLACK;
public static Color LIGHT = Color.WHITE;
public static int PLAYER_ONE = 0;
public static int PLAYER_TWO = 1;
public static int ROWS = 8;
public static int COLUMNS = 8;
public static int MAX_PLAYERS = 2;
}
package core;
import java.awt.Color;
public class Disc {
// member variable
private Color discColor;
/**
* @return the discColor
*/
public Color getDiscColor() {
return discColor;
}
/**
* @param discColor the discColor to set
*/
public void setDiscColor(Color discColor) {
this.discColor = discColor;
}
}
package core;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Game {
// member variables
private ArrayList<Player> players;
private Board board;
public Game(){
// initObjects method call
initObjects();
}
private void initObjects(){
board = new Board();
createPlayers();
printPlayers();
}
private void createPlayers(){
players = new ArrayList<Player>();
for(int i=0; i < 2; i++){
String name = JOptionPane.showInputDialog(null, "Enter player's name");
Player player = new Player();
player.setName(name);
if(i == Constants.PLAYER_ONE)
player.setDiscColor(Constants.DARK);
else if(i == Constants.PLAYER_TWO)
player.setDiscColor(Constants.LIGHT);
Player.add(players);
}
}
private void printPlayers()
{
System.out.println("The game has the following players:");
for(Player name : getPlayers())
{
System.out.println("Player " + name.getName() + " is playing disc color " + name.getDiscColor());
}
}
/**
* @return the players
*/
public ArrayList<Player> getPlayers() {
return players;
}
/**
* @param players the players to set
*/
public void setPlayers(ArrayList<Player> players) {
this.players = players;
}
/**
* @return the board
*/
public Board getBoard() {
return board;
}
/**
* @param board the board to set
*/
public void setBoard(Board board) {
this.board = board;
}
}
package core;
import java.awt.Color;
public class Player {
private String name;
private Color discColor;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the discColor
*/
public Color getDiscColor() {
return discColor;
}
/**
* @param discColor the discColor to set
*/
public void setDiscColor(Color discColor) {
this.discColor = discColor;
}
}
public class Othello {
public static void main(String[] args) {
Game game = new Game();
}
}
最佳答案
变量board
是Disc
的2D数组。Disc
没有方法setColor()
正确的方法名称是setDiscColor()
关于java - 用Java初始化Othello Game Board,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553909/
我刚刚研究了heuristic functions,但是找不到关于黑白棋启发式函数的想法(Othello),我只需要一个很好的想法来对板的某些状态进行评分 我想到了: 计数移动次数 盘数 并计算转角处
我正在创建一个玩黑白棋的简单引擎,使用带 alpha beta 削减的 minimax。它玩得很好,但有时我会得到一个奇怪的索引越界异常(靠近残局,总是)。 这是我的算法 private float
我目前正在尝试为奥赛罗制作一个好的 AI,并且已经使用 Minimax 算法完成了。然而,当我尝试使用 alpha-beta 修剪进行更深入的搜索时,该算法似乎运行得很糟糕。我用 Wiki 和 Ber
在最近的一项任务中,我们的任务是创建Reversi/Othello AI,它可以在 1s 下做出有效的移动。我从一个简单的机器人开始,它采用所有可用的 Action 并根据带有值的棋盘对它们进行评分。
我是一名优秀的程序员,十分优秀!