Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C++] Chess game Terminal

Name: Snake4D 2012-01-11 12:05

Hi,
I'm trying to make a little chess game,
in C++, is in terminal because still I don't know a good GUI package for C++ sorry I'm n00b...

btw I got to print out the board:
like this:
[code]
-|--a-|--b-|--c-|--d-|--e-|--f-|--g-|--h-|
8|-bR-|+bk+|-bB-|+bQ+|-bK-|+bB+|-bk-|+bR+|
7|+bP+|-bP-|+bP+|-bP-|+bP+|-bP-|+bP+|-bP-|
6|----|+--+|----|+--+|----|+--+|----|+--+|
5|+--+|----|+--+|----|+--+|----|+--+|----|
4|----|+--+|----|+--+|----|+--+|----|+--+|
3|+--+|----|+--+|----|+--+|----|+--+|----|
2|-wP-|+wP+|-wP-|+wP+|-wP-|+wP+|-wP-|+wP+|
1|+wR+|-wk-|+wB+|-wQ-|+wK+|-wB-|+wk+|-wR-|
[\code]

and one can tell like in chess with the sentence "(e2:e4)" to move the piece from e2 to e4

but now what I need to make a AI?
I'll paste the code in pastebin so you can have a look:

Name: Anonymous 2012-01-11 12:06

The jews are after me.

Name: Snake4D 2012-01-11 12:10

Name: Snake4D 2012-01-11 12:12

Name: Anonymous 2012-01-11 12:13

And now your code will live here eternally, for everyone to see.

#ifndef PIECE_H
#define PIECE_H

#include <iostream>
#include <map>
#include <string>

#define DEBUG

#define PRINTVAR(VAR) \
std::cerr << "DEBUG "<< #VAR << ": "<< VAR << " at line: " << __LINE__<< " in file: "<< __FILE__ <<std::endl

enum PiecesID {
    NONE = 0,
    PAWN,
    KNIGHT,
    BISHOP,
    ROOK,
    KING,
    QUEEN,
};

enum ColorID {
    colNONE = 0,
    BLACK,
    WHITE
};

class Piece {
private:
    PiecesID idPiece;
    ColorID color;
public:
    Piece():idPiece(NONE), color(colNONE){}
    Piece(PiecesID pid, ColorID cid):idPiece(pid),color(cid){}
   
    PiecesID const& getId() const {return idPiece;}
    PiecesID& setId() {return idPiece;}
   
    ColorID const& getColor() const {return color;}
    ColorID & setColor(){return color;}
   
};

#endif

Name: Anonymous 2012-01-11 12:14

#ifndef BOARD_H
#define BOARD_H

#include <sstream>
#include "Piece.h"

typedef std::pair<int,int> rcPair;

std::pair<int,int> rcFromStr(std::string str);
std::string strFromRC(int row, int col);


class MAPidSTRING{
private:
    std::map<PiecesID,std::string> idToStr;
    std::map<PiecesID,std::string> idToOneLetterStr;
    std::map<ColorID,std::string> idColToStr;
public:
    MAPidSTRING();
    std::string const& operator[](PiecesID ID);
    std::string const& getOneLetterStr(PiecesID ID) {return idToOneLetterStr[ID];}
    std::string const& getColToStr(ColorID ID){return idColToStr[ID];}
};

class ChessBoard {
private:
    Piece board[8][8]; //row column
   
    MAPidSTRING idStr;
public:
    ChessBoard();
    Piece const& getPieceAt(int row, int col) const {return board[row][col];}
    bool isEmpty(std::string pos);
    void putPiece(std::string pos, Piece p);
    void removePiece(std::string pos);
    void movePiece(std::string fromTo);
    Piece const& getPieceAt(std::string pos) const;
    rcPair getRowColAt(std::string pos) const;
    void printBoard();
};

#endif

Name: Snake4D 2012-01-11 12:15

Name: Anonymous 2012-01-11 12:15

Forget it, it's EXPTIME-complete.

Name: Snake4D 2012-01-11 12:17

Name: Snake4D 2012-01-11 12:19

Name: Snake4D 2012-01-11 12:21

Name: Anonymous 2012-01-11 12:52

Chess AI??
No wai.
You mean one that doesn't move chess pieces randomly?
(It's AI too, that's how I usually for the first few moves play)
I can only contribute simple ones.
Search algorithm, makes some move permutations for the next 3-4 moves(fuckload complexity) and put some weights on taking a figure + (weight for different figures) and - for losing a figure
This should be good enough for any CS 101 course, unless your program is gonna play against Bobby Fischer(btw he's dead)
Or just hardcode all possible moves(lol).

Name: Snake4D 2012-01-11 12:55

>>12
    >Or just hardcode all possible moves(lol).
hardway...

btw a simple one that moves pieces like you said is great... do I need something in particular? or store the moves in a boolean board will work?

Name: Anonymous 2012-01-11 12:56

Why don't you just get a github account or something to that effect instead of spamming a bunch of pastebin links?

Name: Snake4D 2012-01-11 12:57

>>14
I'm still learning... :(

Name: Anonymous 2012-01-11 12:58

>>13
Go away. You suck.

Name: not op 2012-01-11 13:00


 -|--a-|--b-|--c-|--d-|--e-|--f-|--g-|--h-|
 8|-bR-|+bk+|-bB-|+bQ+|-bK-|+bB+|-bk-|+bR+|
 7|+bP+|-bP-|+bP+|-bP-|+bP+|-bP-|+bP+|-bP-|
 6|----|+--+|----|+--+|----|+--+|----|+--+|
 5|+--+|----|+--+|----|+--+|----|+--+|----|
 4|----|+--+|----|+--+|----|+--+|----|+--+|
 3|+--+|----|+--+|----|+--+|----|+--+|----|
 2|-wP-|+wP+|-wP-|+wP+|-wP-|+wP+|-wP-|+wP+|
 1|+wR+|-wk-|+wB+|-wQ-|+wK+|-wB-|+wk+|-wR-|

Name: Snake4D 2012-01-11 13:02

>>17
I tried to do that too but didn't worked

Name: Anonymous 2012-01-11 13:03

The jews are after me.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:06

I think it's easier to just write the chess program itself, the AI, and the GUI as three different things. After that, you can just link everything together using getters and setters.

Name: Snake4D 2012-01-11 13:07

>>20
this is what I'm trying to do...

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:08

In other words, just turn this into "abusing message paassing" 101.

Name: Snake4D 2012-01-11 13:12

>>22
>abusing message passing
what does this mean?

Name: 2012-01-11 13:14

2012
not using unicode for chess pieces

IHBT so hard that it hurts

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:17

>>23
Have you ever read SICP? If so, the books talks about this model. Now just extend this basic idea to what you're doing. If not, then I guess I'd have to agree with the regulars here and tell you "Read SICP."

Name: Snake4D 2012-01-11 13:19

>>25
overheading for now is not a problem...

Name: Anonymous 2012-01-11 13:20

>>25
You've been around long enough sadly that you should be able to call yourself a regular as well.

Name: Anonymous 2012-01-11 13:24

>>25`
>kodak
>he's back

Name: Anonymous 2012-01-11 13:24

>>24
Glad I'm not the only one thinking this

Name: Anonymous 2012-01-11 13:27

>>25
Kodak, this is your daily reminder that the statement every subset of a countable set is also countable is absolutely true, never fails and is mathematically proven.

Name: Anonymous 2012-01-11 13:27

OP, read xboard protocol - you don't need to write gui.

Cool story time:
I tried to write chess AI once, even connected it to xboard and tested on several Guests at FICS  Guess what, it appeared that opening books ARE important, as guests were not patient enough to wait while my almighty AI calculated start position score to  start with its favorite Nf3. On the bright side my AI is undefeated after 3 games since people aborted the game at turn 1.

Name: Anonymous 2012-01-11 13:27

>>27
I really think the OP would have an easier time with this project if he had read/absorbed the stuff in SICP.

Name: Anonymous 2012-01-11 13:28

>>31
Are you trolling or are you just plain stupid?

Name: Anonymous 2012-01-11 13:29

Why isn't Kodak calling this guy a mental midget who should scrub another toilet?

Name: Anonymous 2012-01-11 13:30

>>31
I have a yahoo checkers AI program that can defeat pretty much defeat anyone is less than a minutes. Seriously. I actually have this thing running in Badger Bridger right now.

Name: Anonymous 2012-01-11 13:32

>>35
You are aware how much simpler checkers are from chess?

Name: Anonymous 2012-01-11 13:33

>>36
No, but I know enough to realize what's involved in this kind of a project -).

Name: Anonymous 2012-01-11 13:34

>>36
Shouldn't that be "... how much simpler Checkers is compared to Chess?"?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:35

>>36
I believe I have a chess AI engine on my SPARC machine at home that can pretty much clown anyone on Yahoo Chess in less than a minute.

Name: Anonymous 2012-01-11 13:37

http://www.instantchess.com/

/prog/ chess thread, let's do this shit

Name: Anonymous 2012-01-11 13:37

>>38
The checkers AI engine that I use on Yahoo needs both a strong opening engine and a strong closing one. For reasons that I don't understand, I can't have both.

Name: Anonymous 2012-01-11 13:39

Kodak seems a lot less suicidal today, I think he has taken his pills.

Name: Anonymous 2012-01-11 13:39

>>38
I has no idea, I left high-school a while ago and propar grammuh is leafing me with every second.

Name: Anonymous 2012-01-11 13:40

>>43
Now your spelling is incorrect.

Name: Alpha Male !gD3Op2fhHs 2012-01-11 13:44

Snake4d brah, I just wanted to let you know that you should keep doing what you're doing, haters gonna hate.

Name: Anonymous 2012-01-11 13:49

So Kodak is being nice and helpful. Some other dude is spamming a thread about undefined behavior. Nobody is being called mental midgets who should scrub another toilet, tell me, is this bizarro /prog/?

Sorry for shitting up your thread Snake4d.

Name: Anonymous 2012-01-11 13:52

>>46
Is this the real life? Is this just fantasy?

Name: Anonymous 2012-01-11 13:54

>>46
The weird part is that the imageboards are up.

On topic:
Since op is doing it in a terminal means its super-basic.
He should just make something that moves the pieces randomly
unless a piece can score or is in imminent peril.

Name: Anonymous 2012-01-11 14:01

>>48
How does terminal imply super-basic?

Name: Anonymous 2012-01-11 14:04

>>49
Excluding 'in-house' testing.
Silly embedded software.
Basic school projects.
When was the last time you made a purely console app requiring more than 3 inputs?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:09

>>49
>>48 doesn't know what he/she/it's talking about. Maybe it should shut up and go scrub a toilet.

Name: Anonymous 2012-01-11 14:11

>>51
Maybe it should shut up and go scrub a toilet
Now we're talking.

Name: kodak_gallery_programer !!kCq+A64Losi56ze 2012-01-11 14:12

>>50
A lot of OS's make a distinction between the terminal and the console. But I wouldn't expect a mental midget like yourself to know such a subtle, but important difference.

Name: Anonymous 2012-01-11 14:12

Ahh yeah.

Name: Anonymous 2012-01-11 14:14

>>53
But I wouldn't expect a mental midget like yourself to know such a subtle, but important difference.
Kodak-kun, welcome back.

Name: Anonymous 2012-01-11 14:16

He managed to stay nice for over an hour, that's impressive.

Name: Anonymous 2012-01-11 14:17

>>53
This is like the time with char[] not being a string.
So discerning blue from indigo is the only thing you get right.
Are you by any chance a woman?

Name: Anonymous 2012-01-11 14:18

appropriately named chess engine is appropriate: -

http://www.glaurungchess.com/viper/

failing that

google 'chess engines'

Name: Anonymous 2012-01-11 14:20

>>57
This one is fighting back, you're in for one helluva ride bro.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:23

>>57
And what happens if I do something like

int getline(char s[], int lim) {
  for(i = 0; i<lim-1 && (c = getchar()) != EOF && c !='\n'; i++)
    s[i]=c;
}

Is s[] still a string you mental  midget? The answer is no because there is no '\0'. Now go scrub another toilet you fucking idiot.

Name: Anonymous 2012-01-11 14:24

>>60
Well first you would have to declare "i".

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:27

>>57
Also, what happens if the underlying device is a socket()? How do you see fucking output? That is why some operating systems make a distinction between the terminal and the console.

Again, you're stupid. And again, you have no real future as a computer programmer.

Name: Anonymous 2012-01-11 14:28

>>60
Now go scrub another toilet you fucking idiot.

Sure is kodak.

Name: kodak_galleryprogrammer !!kCq+A64Losi56ze 2012-01-11 14:29

>>61
Well, in this case, 'i' would have what is known as 'external linkage'. In other words, I wouldn't have to declare it in this function.

Name: Anonymous 2012-01-11 14:30

>>63
Look up the defintion of a "string" in one of the ANSI/ISO C standards you retard.

Name: Anonymous 2012-01-11 14:31

>>64
Why not just use a static int i at the beginning of your file?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:32

>>63
More on less, in C, a string is an array of characters followed by a '\0'. In this case I don't have a '\0'. Therefore it's not a string. Now shut up and quit arguing with me. Unlike you, I work as a programmer.

Name: Anonymous 2012-01-11 14:33

>>65

LOL what? I'm not even part of this string debate.
off me.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:33

>>66
Standard industry practices dictate that such crap has to be confined to a seperate header file.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:35

>>68
Well, I can't tell you from the idiot computer science major who can't land a programming job.

Name: Anonymous 2012-01-11 14:36

>>70
He just wrote LOL so you can tell him off for that.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List