Hot answers tagged

43

Having a "Map object that keeps track of all the cells to which it can travel" looks to me like an example of premature optimization. Instead of remembering all those cells for each piece "just in case it could become slow", why not give a piece a method with the board as parameter, which returns the related List<Cell> (or Map<Direction, ...


22

My suggestion is to make things as simple as possible. The more information you give to an object, the more complex it becomes, and the harder it is to keep track of it. Let's break your program down into layers. What is there? The pieces. They only know what kind of piece they are, and what color they are (black or white) The board. It knows only about ...


19

2072-rated chess player here. I made this website in pure JavaScript over a weekend. It's not a chess engine (I designed it to create entertaining opening positions as sort of a perverse Chess960 engine), but it's a starting point. The source code is here. There are a lot of complications involved in making a functional board. These include: First, ...


14

The problem with "chess program" as a concept is that there are many pieces which can absorb a lot of time, and not necessarily interest you at the moment. You can spend years just working on graphics, or an alpha-beta search, or a visualization to help develop for the search engine, or... well, there are lots of pieces. I recommend finding an open source ...


13

The answer is to stop designing, since you don't have enough experience to know what to do, and start coding something. Maybe start with just pawns; add functions that can calculate the legal moves if there are only pawns on the board. Then add a king and see what that does to your code. And so on. I have a lot of experience coding, and I still mostly ...


11

I wish to write a chess AI which simulates the way I think over the board, using C++. Awesome! My focus is on writing the algorithms for choosing moves (decision making), not defining the board and pieces. Er, huh? To my knowledge, most chess programs written to date are focused on taking advantage of the computer's calculating powers Well yes, ...


9

If you are familiar with the rules of chess, a good starting point about basic techniques is http://www.frayn.net/beowulf/theory.html An extensive collection of Materials and links you can find here: http://chessprogramming.wikispaces.com/ And third: Learn from others code. Have a look at the sources of Crafty. It's the leading open source engine. Very ...


6

The number of all possible possitions involving KBBK and a checkmate is not that great at all: 32 squares for the light-squared bishop * 32 for the dark-squared bishop * 62 for the White king (64 - 2 already taken by both bishops) * all squares where the Black king is checked by one of the bishops (it must be in check, otherwise it's not checkmate yet - or ...


6

Min-Max search (with or without ABP) is not supposed to "build the complete search tree" in memory. It is usually implemented as Depth First Search tree traversal, which traverses the complete search tree, but does not store it completely. In fact, at each point in time, there is only one node per level required in memory, so the memory usage is actually ...


5

I think your problem scope falls exactly into the purpose of R, though I have never written or worked with R. I have heard good things about it, and would strongly suggest you start looking into it. http://www.r-project.org/ Coming from python this will be a large shift I'm betting since it's functional, but I don't know how pure it is so it may not be too ...


4

This is a case of premature over-design. The pieces don't need a pointer to the board. Just pass the board to the 'generateMoves' method. You don't even need objects for the individual chessmen. All pawns are alike, so you only need one Pawn instance. Also, by the laws of chess, there is a game state that is also needed to correctly generate moves. ...


4

To my knowledge, most chess programs written to date are focused on taking advantage of the computer's calculating powers (aka brute force method). My program will be different in that the focus is going to be on emulating human thinking (in this case my own way of thinking which is actually highly organized). There are quite a lot of possible chess games (...


4

Without any precalculated tables, you can just build a standard chess playing engine (not specifically for endgames). Look, for example, here for a starting point. To optimize such an engine for endgames, you can try to automatically adapt your evaluation function whenever you identify a "known endgame" situation for which you have a specific evaluation ...


4

Already a good answer here, but I try to highlight the problem from a slightly different point of view. When you are going to implement a full retrograde analysis for KBBK, you have to generate all KBBK positions, which are less than 32*32*62*61*2. The "32" is the number of squares for the bishops, the "*2" takes into account which player moves next; and not ...


4

Imagine you've got a function that evaluates the game board and returns a score, where large positive scores mean you're doing well and large negative scores means you're doing badly. Now imagine that for each possible position that a piece can move to, for each piece on the board, you calculate what the score would become and choose the move that results ...


4

Think of an object as a value, just like a number or a string. That value represents a concept in the problem you’re trying to solve. For example, you might use an int to denote a distance in miles, or a number of points, or a set of Boolean flags. The value has no meaning on its own, but it does have an interpretation. Whenever you create a value, you want ...


4

Sure. Your chessboard (or the unblocked cells) form a graph, where each cell is a vertex of the graph, and each allowed knight-move from one node to another defines an edge. The shortest path for the knight then can be found by a simple breadth-first search. To implement this, use a 2D integer array for representing the grid. Simply assign the value zero ...


3

Instead of peer to peer, why not have a central server in which connections are handled and the server's responsibility is to connect the peers together. This also facilitates easier security, acquisition of IP Address and other information that could be kept for storage by the server. A nice threaded-server in which each connection causes server to spawn ...


3

I assume you already know about the concept of Min-Max, trees and pruning, heuristic and other basics and what I write here are just some details that might have been underestimated. I with company a friend wrote our own chess engine sometimes ago. I share some issues and ideas we had and I hope you find them useful. Since we both were java programmers our ...


3

As mentioned, there is nothing terribly hard about build a chess engine. Perhaps, you should concentrate on how wish to use and (potentially) deploy this application as this will probably determine your choice of language. If this is just a fun exercise, you may want to code it in Javascript and deploy it as a web page. If you never want to make it into a ...


3

The other answers already responded how you could do what you asked for. I want only to point out here that neither OOP nor design patterns (yes, they are quite different things) should be used just for the sake of using them. They are tools and, as such, they should be chosen according to the purpose you want to reach, not the other way around. I can't ...


2

I ported a simple chess program as a means of learning the Forth language. It turned out to be a great fit to this very imperative problem, and I learned a lot. The open stack allowed me to implement alpha-beta search in a unique fashion which gave me greater insight into the algorithm. One would think that functional programming would be great for chess ...


2

As per your edit, you're up to the stage of defining 'legal' moves. There are two ways of describing moves in chess. Descriptive notation and Algebraic notation. What you probably want is a function that takes the piece, starting position and ending position as parameters. eg. Knight from QN1 to QB2 is invalid, but Knight from QN1 to Q2 is valid. ...


2

When I read your requirements, I immediately thought of using R, like @JimmyHoffa. In addition, I have done a great deal of programming in R (and Python). I think R is ideal for this kind of work because of: The large amount of statistical tools readily available. Think of Princple Component Analysis (PCA), all kinds of optimization techniques, etc. And if ...


2

Figuring out the legal moves available for a particular piece on a chess board in a particular chess position is very situational, especially when considering pawns...1 space except when it is on its starting position, then two, and then throw in captures and en passant captures...so building an array of moves that are "mechanically" possible is a bit hairy ...


2

The "mates in 0" would be the positions that the king is in checkmate. Konrad gave a way to brute-force them through 444k positions, but we can do significantly better than that. The black king must be on the edge of the board, so that gives 28 positions. One of the bishops must be giving it check; there are only 7 spots that's possible. The other bishop ...


2

A bishop can go to the field numbered +7 or +9, and possibly from there to the fields numbered +14 and +18. That last part you can check with a loop: how often can you do a +7, how often a +9? There are two limits to this: other pieces (which can be captured, but must be then removed) and the board edges. For the bishop, that means you can't do a +7 from ...


2

Creativity As you noticed yourself, this way of proceeding slows down your own brain, which puts itself in a comfortable passive mode. We all know that reading great novels, will not make us good writers ! Furthermore, you limit yourself to already existing designs. This will prevent you from making real breakthrough, innovate radically and differentiate ...


2

This is one of those situation where the human mind have an advantage over a computer. It is fairly simple to for a human to decide if a position in chess is a check mate or not. We can discard most moves as having no relevance to the position. Creating an algorithm that discards those moves is quite tricky. The simple solution of just going through all ...


2

When you are generating all possible moves and evaluate them for the best, you are for sure taking into account the value of pieces that might be taken. Just use the same method, and give the King a very high value; that is the usual approach. There is no magic shortcut to recognize a checkmate - remember it is defined as 'the King will be unavoidably ...


Only top voted, non community-wiki answers of a minimum length are eligible