Page 42 of 52 FirstFirst ... 324041424344 ... LastLast
Results 411 to 420 of 513

Thread: The Primal Journeys of Grok page 42

  1. #411
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    Primal Fuel
    Yesterday I drove down to Gardnerville to visit my friend Art at his Grandmother's house. Art offered me a piece of cake that his Grandmother made and I took a small bite just to taste. I was amazed at how good it was, his Grandmother must be an incredible cook because that was some of the best cake I've ever had. It reminded me a bit of gingerbread and cinnamon and apples. After a few minutes, I went back over to the plate and finished off the entire piece he offered me. Art said the cake was a week or two old which was unbelievable because it was still moist. I hope to get a chance to taste one of her dinners some time. However I checked their food stores and they didn't look like they were eating very primal. A lot of canned fruit and corn and beans and there was cake and cookies and a big tub ice cream in the freezer.

    I got in a few games of chess while I was there. I crushed Art, I remember the last time I played him he did pretty well against me and almost beat me. However, I've been studying the game a lot in the past couple of months, and he probably hasn't played in a year or more when he last played me. It was a good feeling knowing how quickly I can beat an amateur in chess now. Although, I bet if I went to a chess club I'd get my clocked cleaned. Speaking of clocks, I'm probably not so good playing under time pressure either.

    I ordered some books from Amazon on building Android applications. I'm hoping they arrive tomorrow. I've got an Eclipse environment up and running and I got a simple "Hello World" application launching on my phone and in the emulator from Eclipse. Hopefully these books will speed up my learning process. There are some interesting frameworks out there for Android which I looked into, including PhoneGap.

  2. #412
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    Over the weekend I spent some time working on my web based chess application. One of the problems with creating a user interface for a chess game is that one of the expected features of a modern GUI is to highlight all the possible legal moves for a selected piece.

    Trying to come up with logic to describe how chess pieces move on a board to a computer is a difficult task. I e-mailed someone else who wrote a chess GUI and he said he spent three months on the problem. I began looking around at source code to see how other people did it, and they all involve bitboards which are binary representations of chess boards, and complex bitwise operations which are difficult to understand.

    In the end, I figured out a way to query all possible moves from the Stockfish chess engine. You can tell the engine to give a list of the top 500 moves for a given position at depth 1 which means it will not search more than one half-move, thus giving you a simple list of all legal moves for the current player.

    I then set up a chess engine server running Stockfish, and wrote a PHP web service to open up a socket to Stockfish and send it commands and receive output from the engine. I then wrote a simple web query[1] to give a list of legal moves for a given FEN string.

    Next, I wrote a Javascript function to query this page using an AJAX call to get the legal moves for me. I can then use this data to properly highlight legal moves. The finished product is here[2]. If you click on a white piece, it should highlight the squares it can move to. This requires my chess engine server to be running though.

    The next task will be to get this working on an Android device. I got a PhoneGap hello world application running. Now I need to figure out how to add the Stockfish code to my application and compile that for a built-in chess engine on the cell phone. I can then use the built-in engine for move generation purposes.

    [1] http://mobilewebdevs.info.tm/valid_m...R+b+KQkq+-+0+1
    [2] Chess

  3. #413
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    I went to Starbucks this evening just before they closed and got a coffee, and I had a nice long nap in the middle of the day, so I should be up late tonight. The barristas drew a heart on my coffee cup.

    I run my web server on my local machine here at home. My ISP usually assigns a new IP address to me every time I reconnect, so I needed to set up a domain which would always map to my current IP address. I set up a free domain through FreeDNS[1], and then configured my dd-wrt router to automatically update my domain settings every time I get a new IP address.

    So now I have a free domain name which automatically routes to my home computer which runs my web server. As long as I keep my PC on all the time and stay connected to the internet, my web site[2] should be functioning.

    I just put up a real simple web page for now, I'll make it better later.

    [1] FreeDNS - Free DNS - Dynamic DNS - Static DNS subdomain and domain hosting
    [2] Mobile Web Developers

  4. #414
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    I have decided to start using the Google Chrome[1] browser for my default web browsing for now. Many of the development tools in chrome have improved significantly in the past year. I can actually use chrome to do remote Firebug like debugging on a webapp on my android phone which is pretty darn cool.

    I remember when I was developing the official Dilbert mobile application, there would always be rendering bugs on the cell phones which would be difficult to debug without having a tool like firebug.

    I have been using chrome for a couple of days now, and I've spotted some pretty annoying and serious issues with it. However, I'm used to bugs since I run Fedora linux on all my machines. However, there are some serious advantages to using chrome as well, like the seamless integration it has with google apps like gmail, YouTube, google wallet, etc which work better under chrome. Also, flash crashes a lot on recent firefox builds in Fedora which I don't get with chrome, so overall I think chome is better than firefox, but some sites I still need to go back to firefox.

    I've been checking out a new programming language from Google called Dart[2]. Dart is supposed to be a replacement for Javascript. Anyone who has ever programmed Javascript knows how ugly that language can be. The cool thing about Dart, is that I can program my logic in a nice structured manner, then compile the code to Javascript.

    Dart also runs on the server as well. So instead of Javascript on the client, and PHP on the server, you can have dart code on both client and server.

    I'm going to try and rewrite what I've written so far on my chess web application experiment using Dart. On the server side, I have a chess engine server written in tcl which I don't even need to be running. I have a socket on my php application going to the chess engine server, which creates a socket to the actual chess engine, but I shouldn't need to use the tcl code. I should be able to create a socket directly to the chess engine from PHP. However, I want to rewrite it all in Dart.

    My plan for the server is to open a socket connection between the web server and the chess engine application which will be Stockfish using the Dart programming language. Then I will use a websocket[3] to listen for web connections so clients will be able to talk directly to the engine. It should be interesting to see if I can get it all working.

    [1] http://google.com/chrome
    [2] Dart: Structured web apps
    [3] WebSocket - Wikipedia, the free encyclopedia
    Last edited by Grok; 08-09-2012 at 09:46 AM.

  5. #415
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    Yesterday I managed to get the basic chess board working under dart which loads in a position from a FEN string. You can see the new program here.[1] you should not need a dart enabled browser to see it work since I have compiled my code into JavaScript.

    This morning I began working on a server side application so the web page can talk to a chess engine running on my machine. Dart has it's own HttpServer class that has a WebSocketHandler, making HTTP5 WebSockets[2] really easy to set up[3].

    I am really impressed with Dart. Google has hired some top engineers to work on this. The Dart language is in its infancy right now, but I have a feeling it will be the next big thing on the web and will eventually kill JavaScript, and maybe even PHP.

    Here is some sample Dart code...
    Code:
    #library('dartchess');
    
    
    #import('dart:html');
    #import('fen.dart');
    
    
    class Board {
      // Define HTML for chess pieces
      static final String WHITE_KING  = "♔"; // ♔
      static final String WHITE_QUEEN = "♕"; // ♕
      static final String WHITE_ROOK  = "♖"; // ♖
      static final String WHITE_BISHOP= "♗"; // ♗
      static final String WHITE_KNIGHT= "♘"; // ♘
      static final String WHITE_PAWN  = "♙"; // ♙
      static final String BLACK_KING  = "♚"; // ♚
      static final String BLACK_QUEEN = "♛"; // ♛
      static final String BLACK_ROOK  = "♜"; // ♜
      static final String BLACK_BISHOP= "♝"; // ♝
      static final String BLACK_KNIGHT= "♞"; // ♞
      static final String BLACK_PAWN  = "♟"; // ♟
      static final String EMPTY_SQUARE= " ";
    
      static final int NO_PIECE = -1;
      static final int BLACK_PIECE = 0;
      static final int WHITE_PIECE = 1;
    
      Fen fen;
      int colorToMove;
      String whiteBackgroundColor;
      String blackBackgroundColor;
    
      // Construstor method.
      Board() {
        colorToMove = WHITE_PIECE;
    
        // Retrieve black and white background colors from the applied CSS styles.
        whiteBackgroundColor = document.query("#a8").style.backgroundColor;
        blackBackgroundColor = document.query("#b8").style.backgroundColor;
    
        resetBoard();
      }
    
      // Retrieves the contents of a square on the board.
      String getSquare(String square) => document.query("#${square}").innerHTML;
    
       // Sets the contents of a square on the board.
      setSquare(String square, [String value = EMPTY_SQUARE]) =>
          document.query("#${square}").innerHTML = value;
    
       // Sets contents of square referenced by X and Y coordinates.
      setSquareByIndex(num x, num y, [String value = EMPTY_SQUARE]) =>
          setSquare("${"abcdefgh"[x]}${y.toString()}", value);
    
      // Retrieve rank for a given square.
      int getRank(String square) => Math.parseInt(square[1]);
    
      // Retrieve column for a given square.
      int getColumn(String square) => square.charCodeAt(0) - 96;
    
      // Determine which color piece is on a given square.
      int pieceColor(String square) {
        int color = NO_PIECE;
    
        // Get piece value for given square.
        String piece = getSquare(square);
    
        // Determine piece color.
        switch(piece) {
          case WHITE_KING: case WHITE_QUEEN: case WHITE_ROOK: case WHITE_BISHOP: case WHITE_KNIGHT: case WHITE_PAWN:
            color = WHITE_PIECE;
            break;
          case BLACK_KING: case BLACK_QUEEN: case BLACK_ROOK: case BLACK_BISHOP: case BLACK_KNIGHT: case BLACK_PAWN:
            color = BLACK_PIECE;
            break;
        }
    
        return color;
      }
    
      resetBoard() => (fen = new Fen(Fen.INITIAL_POS)).populateBoard(this);
    }
    [1] dartchess
    [2] WebSocket.org | About WebSocket
    [3] Seth Ladd's Blog: Dart Server supports Web Sockets

  6. #416
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    I have implemented a web server written in dart in which a client can communicate directly to a stockfish chess engine on my server.

    The code is amazingly simple, in fact, here it is...

    Code:
    #import('dart:io');
    
    void main() {
      HttpServer server = new HttpServer();
      WebSocketHandler wsHandler = new WebSocketHandler();
      server.addRequestHandler((req) => req.path == "/ws", wsHandler.onRequest);
    
      wsHandler.onOpen = (WebSocketConnection ws) {
        var stockfish = Process.start('stockfish', []);
        var stdout = new StringInputStream(stockfish.stdout);
    
        // Pass output from stockfish to WebSocket.
        stdout.onLine = () => ws.send(stdout.readLine());
    
        // Pass data from WebSocket to stockfish.
        ws.onMessage = (message) => stockfish.stdin.writeString("$message\n");
    
        // Close stockfish connection when WebSocket disconnects.
        ws.onClosed = (int status, String reason) => stockfish.close();
    
        stockfish.onExit = (int exitCode) => ws.close(exitCode, "stockfish: ");
      };
    
      // Listen for connections.
      server.listen('127.0.0.1', 50000);
    }

  7. #417
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    I have completed translating my original chess application from JavaScript to Dart, and I have also programmed in new features to allow you to move a piece, and to get a move from the computer.

    You can actually play the computer for a few moves, but it lacks the ability to do any special moves right now like castling or en passant. However, it's pretty neat seeing my computer make a chess move for me on the web page.

    I've created an account on GitHub, and I plan on moving the sources over there before my disk drive crashes and I lose all my work.

    Dart Chess

  8. #418
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    I put up my source code on github last night.[1] I watched a couple of videos last night on git[2] and learned how it differs from traditional repositories like cvs/svn. I want to practice doing some merging with git, so I'm going to try to create separate branches for fixing a bug or adding a feature, then I will try merging in a couple of code changes and see how it goes. Git looks like a really powerful tool, but you need to learn how to take advantage of its capabilities.

    [1] https://github.com/mobilewebdevs/dartchess
    [2] Git

  9. #419
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    Yesterday I spent a bunch of time watching videos on git, and how reading manuals on git, and playing around with git and using git in my chess project. I've got to say that I'm really impressed. It's amazing how you can context switch between branches almost instantly. I wonder how fast it works on larger projects.

    Anyway, I now fully understand git and why it is way better than traditional scm systems like cvs or svn. I will never use svn again if I don't have to.

    Setting up a code repository in svn is like a half day or full day job if you don't know what you're doing. In git, its just a single command, git init. With svn you have a single repository, whereas in git, everyone has their own repository.

    Also, branching and merging is a piece of cake. You can create a branch for every single modification that you do.

    So, enough of git, yesterday I implemented castling, and en passant, and half move/full move counters in my chess application. You can almost play a full game against my computer now. I just need to do pawn promotion which I'll probably work on next.

    Dart Chess
    https://github.com/mobilewebdevs/dar...commits/master

  10. #420
    Grok's Avatar
    Grok is offline Senior Member
    Join Date
    May 2010
    Location
    LakeRidge Golf Course
    Posts
    3,682
    Primal Blueprint Expert Certification
    HTML 5 is pretty cool, I think it will most likely revolutionize the web. For example, you will soon be able to make and receive phone calls directly from your web browser using SIP[1] and WebRTC[2]. Oh and you won't need any phone service, just an internet connection. I got rid of my phone service a long time ago.

    I moved my chess application over to github.[3] However it still wont work unless my chess engine server is up and running and you can connect to it.



    [1] Session Initiation Protocol - Wikipedia, the free encyclopedia
    [2] WebRTC - Wikipedia, the free encyclopedia
    [3] Dart Chess

Page 42 of 52 FirstFirst ... 324041424344 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •