I'm developing a chess program in Java and considering the following problem: The Rook piece requires implementation for moving in straight lines. The Bishop piece requires implementation for moving in diagonal lines. However, The Queen piece requires implementation for both of the above movement patterns. I can't think of a clean solution to modelling this relationship, I have
我正在开发一个Java程序并考虑以下问题: 该作品需要实施直线移动。 Bishop作品需要实现以对角线移动。 然而, 女王的作品需要实现上述两种动作模式。 我想不出一个干净的解决方案来建模这种关系,我曾经考虑过一些,但没有一个都符合良好的面向对象的设计和高效的代码。 Java不支持多重继承,因此Queen不能借用Rook和Bishop的实现 如果Rook和Bishop延长皇后,我需要将每种运动的逻辑提取为单独的方法,这将严重膨
I am currently working on designing abstract classes for a possible chess game. I needed help regarding how to move different pieces(for example queen, knight) public class MyPiece extends Piece { @Override public boolean canMove(int x, int y) { return (this.x != x && Math.abs(this.y - y) == 1); } } The above code displays a sample for some piece that can just move up and down. I
我目前正在为可能的国际象棋游戏设计抽象类。 我需要关于如何移动不同部分的帮助(例如皇后,骑士) public class MyPiece extends Piece { @Override public boolean canMove(int x, int y) { return (this.x != x && Math.abs(this.y - y) == 1); } } 上面的代码显示了一些可以上下移动的样本。 这不是有效的国际象棋移动。 因此,如果我要移动一个女王我将如何去?简单地说,我们只是假设我们已经有一个由8
I am writing a chess engine in Java, and I would like to print the board with ASCII characters (ie: # for an empty square, K for a king, Q for a queen etc ..). The represention should differentiate black and white pieces. I am looking for method which will have for input a list (or map or array) of Pieces and which will output a string representing the board. I have already a Board object, c
我正在用Java编写一个国际象棋引擎,我想用ASCII字符打印棋盘(例如:#代表空格,K代表国王,Q代表女王等)。 代表应区分黑色和白色的部分。 我正在寻找将输入一个列表(或地图或数组)的方法,并将输出一个字符串表示董事会。 我已经有一个Board对象,包含一个Pieces列表。 件是一个抽象类,有一个位置(x,y)和一个颜色(黑色或白色)。 然后,国王,女王,骑士是执行Piece类的课程。 谢谢 我想你用一个Object代
i'm making a chess game in java, and pawns are giving me a hell of a problem. I honestly don't know why, as their movement is the simplest. Here's the Piece declaration, and the Pawn (extends Piece) declaration. The movement class defines a simple x;y object that i use to mark possible movement targets on the board.. i have a GameHandler class that later depures all impossible move
我正在用java做一个象棋游戏,而棋子给我一个问题。 我真的不知道为什么,因为他们的运动是最简单的。 这是Piece声明和Pawn(extends Piece)声明。 运动类定义了一个简单的x; y对象,我用它来标记棋盘上的可能运动目标。我有一个GameHandler类,稍后将根据游戏规则来处理所有不可能的运动。 但Pawn的动作阵列似乎很干净; 所有其他作品的动作都像奇迹般运作! 提前致谢! 件类 public abstract class Piece{ protect
I need help in designing a Chess game. I've already started but haven't got far as I'm pretty new to Java, new to programming at all actually. Anyway, I have my abstract class Piece and the various pieces as subclasses. I have a method movePiece, in my abstract class, which I want to define for all subclasses. All it currently does is move the piece from one square to another.
我需要设计一个国际象棋游戏的帮助。 我已经开始了,但还没有远到,因为我对Java很陌生,实际上对编程来说是新手。 无论如何,我有我的抽象类Piece和各个部分作为子类。 我在我的抽象类中有一个movePiece方法,我想为所有的子类定义它。 它目前所做的就是将棋子从一个方块移到另一个方块。 我有一个可以容纳一个Piece对象的Square类,该板包含一个64x1的Square数组。 我知道棋子是如何移动的,但我怎样才能真正做到编程
I want to implement a chess game in java. So far I thought of these classes : Piece : an abstract class. All the pieces types are inherit from this class (like Queen , King , Pawn and so on. The class piece will have methods like getLegalMoves() getMovePath(Cords source, Cords dest) that are implemented different in each sub classes. Board : This class will have a 8X8 array of Piece . NULL
我想用java实现一个国际象棋游戏。 到目前为止,我想到了这些类: Piece :抽象类。 所有的棋子类型都是从这个类继承而来的(比如Queen , King , Pawn等等getMovePath(Cords source, Cords dest) ,类中的每个子类都有不同的getLegalMoves() getMovePath(Cords source, Cords dest) 。 Board :这个类将有一个8X8阵列的Piece 。 NULL ref是空方块的含义。 BoardAlgorithms :这个类将包含所有“扫描”算法,例如检查是
Currently fooling around trying to piece together chess but I can't seem to find a easy way to reuse already existing code I have to solve it. The problem lies with checking if possible move is safe or not. My thinking was going through each opposite piece and check if they can move to one of the squares the King can move to. But that does not work well. Tried several ways to either teac
目前无意拼凑国际象棋,但我似乎无法找到一个简单的方法来重用已经存在的代码,我必须解决它。 问题在于检查可能的移动是否安全。 我的想法是通过每个对面的一块,并检查他们是否可以移动到国王可以移动到的其中一个方格。 但是这并不好。 试过几种教Pawn或king的方式,但没有成功。 得到了其他所有工作,但是这两个人一起工作! Board正在使用扩展jButton的8x8正方形数组。 我怎么让国王知道如何在他安全的时候移动一
I just downloaded Java 7u17 on Mac OS 10.7.5 from here and then successfully installed it. In order to do some JNI programming, I need to know where Java installed on my Mac. I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but then I found that the folder is empty. This was confirmed by running ls /Library/Java/JavaVi
我刚从这里下载了Mac OS 10.7.5上的Java 7u17,然后成功安装了它。 为了做一些JNI编程,我需要知道在我的Mac上安装了哪些Java。 我以为在/Library/Java/JavaVirtualMachines/文件夹里面会有一个名为1.7.0.jdk的文件夹,但后来我发现这个文件夹是空的。 这可以通过在终端中运行ls /Library/Java/JavaVirtualMachines/来确认。 我试图寻找它是否安装在别的地方,但似乎没有任何改变。 有人可以告诉我在我的Mac上安装了Java
This question already has an answer here: Parse any date in Java 3 answers You're trying to convert a String in EEEE, MMMM dd, yyyy format with the format of dd/MM/yyyy ... Start by using the correct format for the String you trying to convert, the use what ever format you want to convert it back... SimpleDateFormat from = new SimpleDateFormat("EEEE, MMMM dd, yyyy"); SimpleDateFormat t
这个问题在这里已经有了答案: 在Java 3答案中解析任何日期 您正试图将格式为dd/MM/yyyy EEEE, MMMM dd, yyyy格式的字符串转换成... 首先使用正确格式的String尝试转换,使用任何你想要将其转换回来的格式... SimpleDateFormat from = new SimpleDateFormat("EEEE, MMMM dd, yyyy"); SimpleDateFormat to = new SimpleDateFormat("dd/MM/yyyy"); String value = to.format(from.parse(dateString)); 现在你可以使用类似
I am currently writing test cases for a ContentProvider in my application (which is a checkbook recording app) and I am having a test fail when it is comparing double values. The best way to illustrate this is with code. I have this function that returns ContentValues for an account object to be inserted into the database: private ContentValues getAccountContentValues(){ String testName = "
我目前正在为我的应用程序(这是一本支票簿记录应用程序)编写ContentProvider的测试用例,并且在比较double值时我的测试失败。 说明这一点的最佳方式是使用代码。 我有这个函数返回ContentValues,以便将一个账户对象插入到数据库中: private ContentValues getAccountContentValues(){ String testName = "Capital One"; double testStartingBalance = 3000.00; ContentValues accountValues = new ContentValues