Pages

Monday, November 26, 2012

Life Moves as Pawns on a Board...And More!

Hi everyone!  It's been a while.  Same excuses - lazy, busy, too much Dota, you know how it is.  I hope.

So anyway, I've been doing some things.  Among other stuff such as guitar and Halo 4, I've been working on my code projects and made a bit of progress on some stuff!  Let's get to it.

As you might recall, my chess clone, last time we visited, was completely stupid.  The pieces knew where they could move, but upon trying to do so they made a pawn where the move would go. There were a number of pawn-based revolts on the basis of their value depreciating from the influx of pawns in the market.  But it's fixed now, as you can see.  Yes, there are also moves that shouldn't be there off the board, but I'm still working on that (if you're curious, it has to do with capture moves being a little wonky with my setup).

So there's that.  It's one step closer to a functional clone that I can actually do stuff with, and that's what matters when I can't commit to this stuff full-time.

I've also made some progress on my corpus study tool.  I've got the framework for discovering probabilities of particular sequences, as shown at left.  To explain this, what we have are sequences of words (with an intermediary separator, don't worry about that) in pairs, followed by a final word and the number of times it occurs after the pair.  You might also notice I'm clearly using The Call of Cthulhu as my test corpus.  The next step is to aggregate by initial words and then make a list of all the possible finals with their counts, and then finding a final probability of some sequence of three words ending with a word can be determined pretty trivially.

Not sure what I'll do with it once I finish that step (which might happen tonight), but it'll be more or less complete for English/Latin symbol languages sans doing a bunch of stress testing on more Lovecraft and making it not an aesthetic mess.  Then I'll have to work on a method for finding word boundaries in languages such as Japanese or Chinese, which will be a huge mess.  Looking forward to it!

The last project I've been working on is the guitar project, to which I haven't added much.  I just made it possible to do lookups on multiple notes and find scales containing all of them (shown at right).  I've also been trying to figure out how best to implement chord lookups, which in and of itself wouldn't be too hard, but I want to be able to find chord variations (like an Asus4 or Gm7 or however the spirit moves you) and show them (and thus, all possible positions) on the virtual fretboard.  I'll also at some point need to start making this guy graphical.

So, that's what I've been doing, as well as Minecraft and Dota, and I'm probably going to use my 2 free months of XBL fairly soon to kill scrubs in Halo, if anyone ever wants to join me on that just lemme know.  Until next time!

Tuesday, September 25, 2012

Some Day I'll Stop Being Dumb.

Maybe today.  We'll see.  I need to stop taking extended breaks.

SO ANYWAY.  Been busy.  College of Engineering had a career fair last Wednesday, so I showed up all hella snazzy with forty resumes, handed out 18 and can only account for handing out fifteen.  Hm.  Could be worse.  Did get an interview on Thursday that they called me back to request an on-site, which was rad!  It'll be my first experience in actual Cleveland!

Have also been playing a fair amount of guitar lately.  And with that, a bit of working on my guitar notes program.  I made a menu interface!  So now it looks like this:


Also pictured: A segment of my Younha wallpaper because my terminal is partly transparent, and a bunch of random secret folders on my desktop, all accurately labelled.  So in addition to doing what it has always done (show scales), it also lets you choose which type of scale you want to see, and as soon as I'm done writing this it'll let you change the number of frets, too (small oversight).  I also need to get the "octave" out of that display, but whatever.  Of course, typing in either 'q' or 'Q' will exit the program from that screen.

So that's been that guy.  My corpora analysis...hasn't really gone anywhere, but I did recruit a dude to help me with it, so it's on Github.  If you're interested in helping with that guy (seriously fucking EVERYONE I talked to at the career fair wanted me to explain it, and after I did they were all like "how about I give you my card, and you apply further, because this is really cool".  shit looks good), drop me a line (sthara216 at gmail dot dot dash com, but minus the dot dash) and we can talk about it more.

I'm also now technically an officer for the Japanese Student Organization and I'm helping them with technical stuff.  WHOO.  Yeah that's not really interesting news for you readers (all half of a person).  Whatevs.

So anyway, going to try and update this more (eg. at all), so if I stop, call me a bitch and tell me to write more blawg.  I won't be offended.  UNTIL NEXT TIME...

Sunday, June 24, 2012

HAYLE, it's about time.

Yeah, soooo, I've kind of been absent for a while from blogging.  But worry not!  I have reasons!

I'll sum it up as school sucks.  Thankfully my last year of undergrad won't be a mess of overachieving - just normal achieving.  Not necessarily easy, but whatever.

So anyway, I didn't have all that much time for personal projects last quarter, besides playing Dota every once in a while, and so I didn't have much to post about on here anyway.  My other blog, FUCK, was a little too time-consuming for me to continue, so I didn't post on it either.

But now it's summer, and even though I'm working while also taking summer intensive Japanese, I have more free time!  Which means more blog posts for my beautiful friends (like you) to read!

I've started a few things since last quarter ended.  I'll just sum them up here, since I don't really wanna get too into the deets.

  • Started working on a website again.  It sucks and I'm totally aware of that, because I'm a programmer and am thus totally awful at aesthetic design from scratch.  It's disastrous.  But I should probably have one by the time I graduate so I look a little more employable.
  • I got tired of losing the pieces of paper that I wrote down major scales on for playing guitar chords/improv, so I've started writing a Python script to do it for me.  Currently it looks like this:

Kinda hard to see from this, but it has a textual fretboard representation, the scale itself, and every single position on the fretboard belonging to that major scale (and subsequently, to each mode of that scale, which also solves that problem I got tired of doing).  I also wrote a nice looking Python list-pivot function because of this little project.  I want it to do more, like display all the major scales (it doesn't like trying to deal with flats, but sharps work just fine - I know they're more or less equivalent, but I'm a bit of a perfectionist when it comes to code projects).

I've also kind of started writing again!  I don't have any substantial text, but I might start another blog for no purpose than sharing my writings if I start writing enough of them.

That's pretty much all I've been up to lately.  As always, comments and the like are appreciated in the boxes below.  And expect a Fruncoki entry sometime this week! 

Sunday, April 15, 2012

WHERE HAVE I BEEN

I'm such a lazy whore.

Anyway, for anyone who's been keeping up with this at all (probably an empty set), I've been really lazy. That's really it.  Also had a fair amount of work to keep up with, but I've also played fucktons of Dota, so I don't really have an excuse.  Oh well.  Whatevs.

So what's been going on in the world of my chess clone lately?  Well, I have done a few things, including but not limited to:

  • Refactored out the move logic
  • Generalized said logic to both players
  • Validating whether some particular move is indeed legit
  • Screwed up my board logic, and subsequently fixed it
The problem is, they don't really do anything at this point.  For some reason it doesn't actually move pieces when the player selects a valid move.  It just kinda...stops doing anything.  It's really strange.  This is basically the priority when I do work on this.

Logic generalization is irrelevant in the face of the previous issue.  And black pieces don't have moves for some reason.  That'll come after I figure out why pieces don't move.  Whatevs.

So uh, yeah, wasn't much here other than a basic update and a quick "WHERE DID I GO" kind of thing.  Should have more next week!

Monday, March 12, 2012

Chess Pieces are Stupid

Hi everyone!  I know it's been a while since the last post of mine, but I've been busy with finals and am taking a quick break to start this post (and maybe finish?  this reinforcement learning paper I'm reading is kind of hefty reading and a lot more detailed than I'll need...).  So, last time we saw the basic framework for the chess representation, with the board, pieces, and the player data structures.  Since then, I've actually not done very much, but that's because it's been buggy and stupid.

void unitTestWhite(Pieces x, int x_ = 4, int y = 4) {
struct Piece *unittest = new Piece(x);
unittest->setPos(x_, y);
pieces.push_back(*unittest);
//std::cout << "test type: " << unittest->type << endl;
//std::cout << "test2: " << pieces.begin()->type << endl;
delete unittest;
//std::cout << "test3: " << pieces.begin()->type << endl;
//std::cout << pieces.size() << endl;
}

This guy right here is a fucking champion.  Helped me pinpoint so many bugs, and testing each unit's move set would be bitchy without it.  It also has a lot of debug output, but don't mind that.  It doesn't do much special, really, just makes a new piece of type x and puts it somewhere on the board (should have checks for values of x_ and y > 7...done).  The function name is somewhat misleading, as it is in no way required to operate on who's playing white, but I'm lazy.  I'll probably change it once I figure out how to refactor move selection so I can just function call it for both players.

The next big thing I've been working on is the game loop, which is being omitted from this post because it's disgusting and large to transplant into a blog post (seriously, I tried - if anyone really wants to see it, I can email you the current source in all its incomplete glory).  I have encountered so many god damn problems with this loop because C++ iterators are wonky, including and not limited to:

  • kings thinking they are pawns
  • pieces only wanting to move to legal moves down and right (and in between for bishops and rooks)
  • knights thinking they are pawns and sort-of queens
  • pieces suddenly becoming paralyzed
  • pieces exploding upon the realization they have the potential of movement


It's been a bit of a headache, but I'm pretty sure it's mostly fine now.  As for how it works, well, it doesn't really do anything special, but here's some pseudocode anyway:

figure out the current board state and draw
do some fancy aesthetic shit based on whose turn it is
while a move hasn't been made yet
if player's turn, let them click until they click a piece of theirs
show all possible moves for clicked piece
wait for player to make a move
update board and switch turns to opposing player

And that's basically it.  It's not fully complete, as I still need to have actual moves and turn-swapping, but yenno.  After that I can start working on the actual AI, but finishing just this will probably be a fairly slow process as well, since I need to finish a research proposal, continue studying for finals and somehow manage to feed myself food, because the ramen/rice diet of two days is starting to actually hurt.  I should be able to have something by the time spring break comes around, though, and if not in the middle of spring break.  Until then, for my OSU friends who are also killing themselves with finals, I wish you all luck!

As always, comments and whatnot can go in the comments, or you can email me!

Sunday, February 26, 2012

What Is a Chessboard?

Yeah, the current project is chess.  I've decided on this.  Because it's fun, and it'll be a good AI exercise for me down the road.  Also up to now I've made a number of attempts at a blog update only to realize I'd have like a thousand updates on everything cool that I figure out.  So instead, weekly updates!

A week ago, on the whim of not really having anything to do at work while my code ran (apparently analyzing sixteen gigs of genomic data takes a while), I decided to make a chess clone in C++ because I know that language best.  That day I'd made the board minus the border, which was cool, and had some cool text that showed up.  Altogether, nothing too fancy.

Over the week I've finished the board, added the internal representation of the board, created the Player structure, methods to: get the current location of every piece; show the board; reset the board; randomize the board (this was mostly for testing the "show" and "reset" methods, but is kinda cool nonetheless); output the text representation for the board to standard output; and an "initialize" method that doesn't actually do much.  The current image set for my chess clone is actually just letters for the moment, but that'll change in polishing.  Unless I'm really as lazy as I think I can be sometimes.

So, this is intended to be more than a journal of my progress.  I'd also like to get pieces of my code on here so either 1) people can learn from it; or 2) I can learn from other people looking at it and telling me I'm stupid.  Both totally valid.  Without further delay, let's take a look at what I've been doing, starting with the internal representation of the board!


int board[8][8] = {{0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  {0,0,0,0, 0,0,0,0},
  };

Nothing special.  You might be wondering "but why are you using ints?  They don't mean anything to a chess program!"  This is true, at least in a vacuum; but I really like enums.

enum Pieces {
PAWN,
KING,
QUEEN,
ROOK,
BISHOP,
KNIGHT,
BPAWN,
BKING,
BQUEEN,
BROOK,
BBISHOP,
BKNIGHT,
EMPTY
};

This basically assigns each piece type a numeric value, for those of you unfamiliar with enum (it 'enum'erates over a number of identifiers! who'da thunk that programming can make sense?).  Now, the reason I have two sets of piece identifiers is for the two different players, because otherwise you have to integrate display functions with board state retrieval and it's a bit of a mess.  Speaking of board state retrieval...

class Player {
private:
bool color; //true = white, false = black
vector pieces;
public:
Player(bool isWhite) {
color = isWhite;
                        //code omitted for brevity
}
vector getPieceList() {
return this->pieces;
}
};

A wild Player class has appeared!  It has the Piece struct you haven't seen yet as a fundamental part of its definition, but we'll get to that next.  This is basically just a nice way to keep all the player data in one place.  The mostly omitted constructor basically just makes a bunch of new Piece objects, and depending on the color of this particular player (we're abstracting race into a true-false distinction, because we can) puts them in the right places.  It's really verbose because I can't think of a better way to do it without passing it off to some other function, which doesn't really make sense since it only happens once.  I don't think it needs a destructor yet, since games don't actually happen, let alone finish, so yeah.  Now to the Pieces!

struct Piece {
Pieces type;
int x, y; //the position on the board
Piece(Pieces _type) {
type = _type;
}
void setPos(int _x, int _y) {
x = _x;
y = _y;
}
};

This is pretty simple.  Probably a little redundant overall, but whatevs.  The last thing of interest, I think, is the thing that determines the current location of every piece based on each player's list of pieces:

void getCurrentBoardState() {
vector w_piece = w.getPieceList();
vector b_piece = b.getPieceList();
for (vector::iterator it = w_piece.begin(); it < w_piece.end(); it++) {
int tempx = it->x, tempy = it->y;
board[tempx][tempy] = it->type;
}
for (vector::iterator it = b_piece.begin(); it < b_piece.end(); it++) {
int tempx = it->x, tempy = it->y;
board[tempx][tempy] = it->type + 6;
}
}

Again, it's pretty simple, but it worked the first time I compiled with it so I'm kinda proud of it because I'm normally really bad with iterators.  I also really liked how the Piece and Player structures made this so trivial, made me feel good about my design choices.  I'm sure that'll change soon.

So, if you have anything to add, ask about, or comment on, let me know in the comments!

Sunday, February 19, 2012

..People still read this?

Well damn.

Color me confused.

Oh well.  I guess now that I have another blog that I actually regularly update, it wouldn't be a bad idea to reboot this one.  Again.  Yeah.  I intend to keep this one on a somewhat regular update schedule (once every couple weeks or something like that).  Probably more about my personal code projects and random interesting things that happen in my life.  Boring stuff like that.

On that note, about an hour ago, out of boredom and a lack of anything to actually do at work, I decided I'd make a chess clone with SDL.  So far, I have a chess board!  It doesn't have distinct borders.  Not sure how I'll do that, but it should be about ten minutes total to think about it, figure something out, implement it once, realize it's stupid that way, and then implement it more correctly.  That's the usual flow of my coding, at any rate!

The motive behind making a chess clone, aside from just a random and probably fairly quick project, are also so I can make something that has an interesting AI component.  The great thing about chess is it's a game of perfect information (which just means nothing about the game state is hidden), which makes an AI closer to deterministic depending on how good the board evaluation function is.  With, say, a card game, a computer would have to operate almost entirely on probabilities regardless of the quality of the evaluation function just because that's how those games are designed.

So uh, dunno what else I can say here.  I could keep going on and on about how to apply AI to various types of games, but I think I'll save that for someone actually being interested or a post on its own when I've thought about it more.  REBOOT, GO!
/* Custom junk */