JavaScript appears to be disabled. We recommend you enable JavaScript while visiting this site.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Tic-Tac-Toe using Pascal

The following is a really old program (November 2003) written in Pacal using Bloodshed Dev-Pascal (which seems to no longer be updated).

This is the code in main.pas, which it seems is the only file really necessary.

This code is covered by a Creative Commons Attribution-NonCommercial 3.0 license.

program TicTacToe (input, output);
label
     begingame, picknumber, checkmove, checkforwin, compmove, winner, nobodywon, playagain, illegalmove, compcrash, endgame;
var
   playmove, turn, points : integer;
   place1, place2, place3, place4, place5, place6, place7, place8, place9 : char;
   currentplayer, ynagain, lastwinner : char;
begin
     writeln;
     writeln('JRSs Tic-Tac-Toe v1.1');
     writeln('Created by James Skemp - http://jamesrskemp.net/'); {2003.11.09}
     writeln('Version 1.0: 2003.11.09');
     writeln('Version 1.1: 2003.11.09');
     writeln;
     points := 0;
     lastwinner := 'J';
     begingame:
     turn := 0;
     place1 := '1';
     place2 := '2';
     place3 := '3';
     place4 := '4';
     place5 := '5';
     place6 := '6';
     place7 := '7';
     place8 := '8';
     place9 := '9';
     if (lastwinner = 'J') then goto picknumber;
     if (lastwinner = 'X') then goto compmove;
     if ((lastwinner = 'O') and (points <10)) then goto picknumber;
     if ((lastwinner = 'O') and (points >11)) then goto compmove;
     picknumber:
     currentplayer := 'X';
     writeln;
     writeln;
     writeln('     |   |   ');
     writeln('   ',place1,' | ',place2,' | ',place3,' ');
     writeln('     |   |   ');
     writeln('  ---+---+---');
     writeln('     |   |   ');
     writeln('   ',place4,' | ',place5,' | ',place6,' ');
     writeln('     |   |   ');
     writeln('  ---+---+---');
     writeln('     |   |   ');
     writeln('   ',place7,' | ',place8,' | ',place9,' ');
     writeln('     |   |   ');
     writeln;
     writeln('Pick a number that you would like to take (you are ''X''). ');
     readln(playmove);
     checkmove:
     if ((playmove > 9) and (playmove <> 33)) or (playmove < 1) then
      begin
       writeln('Whoops.  That''s an illegal move, try again.');
       writeln;
       goto picknumber;
      end;
     if (playmove = 1) and (place1 = '1') then
      begin
       place1 := 'X';
       goto checkforwin;
      end;
     if (playmove = 2) and (place2 = '2') then
      begin
       place2 := 'X';
       goto checkforwin;
      end;
     if (playmove = 3) and (place3 = '3') then
      begin
       place3 := 'X';
       goto checkforwin;
      end;
     if (playmove = 4) and (place4 = '4') then
      begin
       place4 := 'X';
       goto checkforwin;
      end;
     if (playmove = 5) and (place5 = '5') then
      begin
       place5 := 'X';
       goto checkforwin;
      end;
     if (playmove = 6) and (place6 = '6') then
      begin
       place6 := 'X';
       goto checkforwin;
      end;
     if (playmove = 7) and (place7 = '7') then
      begin
       place7 := 'X';
       goto checkforwin;
      end;
     if (playmove = 8) and (place8 = '8') then
      begin
       place8 := 'X';
       goto checkforwin;
      end;
     if (playmove = 9) and (place9 = '9') then
      begin
       place9 := 'X';
       goto checkforwin;
      end;
     if (playmove = 33) then
      begin
       writeln('Hi James');
       goto playagain;
      end
     else
      goto illegalmove;
     compmove:
     currentplayer := 'O';
     writeln;
     writeln('Computer''s move ');
     {Check for Horizontal win}
     if ((place1 = '1') and (place2 = 'O') and (place3 = 'O')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place2 = '2') and (place3 = 'O')) then begin place2 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place2 = 'O') and (place3 = '3')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place4 = '4') and (place5 = 'O') and (place6 = 'O')) then begin place4 := 'O'; goto checkforwin; end;
     if ((place4 = 'O') and (place5 = '5') and (place6 = 'O')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place4 = 'O') and (place5 = 'O') and (place6 = '6')) then begin place6 := 'O'; goto checkforwin; end;
     if ((place7 = '7') and (place8 = 'O') and (place9 = 'O')) then begin place7 := 'O'; goto checkforwin; end;
     if ((place7 = 'O') and (place8 = '8') and (place9 = 'O')) then begin place8 := 'O'; goto checkforwin; end;
     if ((place7 = 'O') and (place8 = 'O') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     {Check for Vertical win}
     if ((place1 = '1') and (place4 = 'O') and (place7 = 'O')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place4 = '4') and (place7 = 'O')) then begin place4 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place4 = 'O') and (place7 = '7')) then begin place7 := 'O'; goto checkforwin; end;
     if ((place2 = '2') and (place5 = 'O') and (place8 = 'O')) then begin place2 := 'O'; goto checkforwin; end;
     if ((place2 = 'O') and (place5 = '5') and (place8 = 'O')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place2 = 'O') and (place5 = 'O') and (place8 = '8')) then begin place8 := 'O'; goto checkforwin; end;
     if ((place3 = '3') and (place6 = 'O') and (place9 = 'O')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place3 = 'O') and (place6 = '6') and (place9 = 'O')) then begin place6 := 'O'; goto checkforwin; end;
     if ((place3 = 'O') and (place6 = 'O') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     {Check for diagonal win}
     if ((place1 = '1') and (place5 = 'O') and (place9 = 'O')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place5 = '5') and (place9 = 'O')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place1 = 'O') and (place5 = 'O') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     if ((place3 = '3') and (place5 = 'O') and (place7 = 'O')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place3 = 'O') and (place5 = '5') and (place7 = 'O')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place3 = 'O') and (place5 = 'O') and (place7 = '7')) then begin place7 := 'O'; goto checkforwin; end;
     {Check for Horizontal block}
     if ((place1 = '1') and (place2 = 'X') and (place3 = 'X')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place2 = '2') and (place3 = 'X')) then begin place2 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place2 = 'X') and (place3 = '3')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place4 = '4') and (place5 = 'X') and (place6 = 'X')) then begin place4 := 'O'; goto checkforwin; end;
     if ((place4 = 'X') and (place5 = '5') and (place6 = 'X')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place4 = 'X') and (place5 = 'X') and (place6 = '6')) then begin place6 := 'O'; goto checkforwin; end;
     if ((place7 = '7') and (place8 = 'X') and (place9 = 'X')) then begin place7 := 'O'; goto checkforwin; end;
     if ((place7 = 'X') and (place8 = '8') and (place9 = 'X')) then begin place8 := 'O'; goto checkforwin; end;
     if ((place7 = 'X') and (place8 = 'X') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     {Check for Vertical block}
     if ((place1 = '1') and (place4 = 'X') and (place7 = 'X')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place4 = '4') and (place7 = 'X')) then begin place4 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place4 = 'X') and (place7 = '7')) then begin place7 := 'O'; goto checkforwin; end;
     if ((place2 = '2') and (place5 = 'X') and (place8 = 'X')) then begin place2 := 'O'; goto checkforwin; end;
     if ((place2 = 'X') and (place5 = '5') and (place8 = 'X')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place2 = 'X') and (place5 = 'X') and (place8 = '8')) then begin place8 := 'O'; goto checkforwin; end;
     if ((place3 = '3') and (place6 = 'X') and (place9 = 'X')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place3 = 'X') and (place6 = '6') and (place9 = 'X')) then begin place6 := 'O'; goto checkforwin; end;
     if ((place3 = 'X') and (place6 = 'X') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     {Check for diagonal block}
     if ((place1 = '1') and (place5 = 'X') and (place9 = 'X')) then begin place1 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place5 = '5') and (place9 = 'X')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place1 = 'X') and (place5 = 'X') and (place9 = '9')) then begin place9 := 'O'; goto checkforwin; end;
     if ((place3 = '3') and (place5 = 'X') and (place7 = 'X')) then begin place3 := 'O'; goto checkforwin; end;
     if ((place3 = 'X') and (place5 = '5') and (place7 = 'X')) then begin place5 := 'O'; goto checkforwin; end;
     if ((place3 = 'X') and (place5 = 'X') and (place7 = '7')) then begin place7 := 'O'; goto checkforwin; end;
     if (turn = 0) then begin place3 := 'O'; goto checkforwin; end;
     {Check for favorite turn 2 places}
     if ((turn = 2) and (place1 = 'X')) then begin place9 := 'O'; goto checkforwin; end;
     if ((turn = 2) and (place7 = 'X')) then begin place1 := 'O'; goto checkforwin; end;
     if ((turn = 2) and (place9 = 'X')) then begin place7 := 'O'; goto checkforwin; end;
     {Go for place 5 if open}
     if (place5 = '5') then begin place5 := 'O'; goto checkforwin; end;
     {Check for stupid moves}
     {...}

     if (place3 = '3') then begin place3 := 'O'; goto checkforwin; end;
     if (place9 = '9') then begin place9 := 'O'; goto checkforwin; end;
     if (place1 = '1') then begin place1 := 'O'; goto checkforwin; end;
     if (place7 = '7') then begin place7 := 'O'; goto checkforwin; end;
     if (place4 = '4') then begin place4 := 'O'; goto checkforwin; end;
     if (place2 = '2') then begin place2 := 'O'; goto checkforwin; end;
     if (place6 = '6') then begin place6 := 'O'; goto checkforwin; end;
     if (place8 = '8') then begin place8 := 'O'; goto checkforwin; end;

     goto compcrash;

     checkforwin:
      turn := turn + 1;
      if ((place1 = place2) and (place1 = place3)) then goto winner;
      if ((place1 = place4) and (place1 = place7)) then goto winner;
      if ((place1 = place5) and (place1 = place9)) then goto winner;
      if ((place2 = place5) and (place2 = place8)) then goto winner;
      if ((place3 = place5) and (place3 = place7)) then goto winner;
      if ((place3 = place6) and (place3 = place9)) then goto winner;
      if ((place4 = place5) and (place4 = place6)) then goto winner;
      if ((place7 = place8) and (place7 = place9)) then goto winner;

      if turn = 9 then goto nobodywon;
     if currentplayer = 'X' then
      begin
       currentplayer := 'O';
       goto compmove;
      end
     else
      begin
       currentplayer :='X';
       goto picknumber;
      end;

     winner:
      writeln;
      writeln('     |   |   ');
      writeln('   ',place1,' | ',place2,' | ',place3,' ');
      writeln('     |   |   ');
      writeln('  ---+---+---');
      writeln('     |   |   ');
      writeln('   ',place4,' | ',place5,' | ',place6,' ');
      writeln('     |   |   ');
      writeln('  ---+---+---');
      writeln('     |   |   ');
      writeln('   ',place7,' | ',place8,' | ',place9,' ');
      writeln('     |   |   ');
      writeln;
      if currentplayer = 'X' then
       begin
        writeln;
        writeln('You''ve won!  Congrats :)');
        points := points + 1;
        lastwinner := 'X';
        goto playagain;
       end
      else
       begin
        writeln;
        writeln('Sorry :( but you have lost...');
        points := points - 1;
        lastwinner := 'O';
        goto playagain;
       end;

     nobodywon:
      writeln;
      writeln('     |   |   ');
      writeln('   ',place1,' | ',place2,' | ',place3,' ');
      writeln('     |   |   ');
      writeln('  ---+---+---');
      writeln('     |   |   ');
      writeln('   ',place4,' | ',place5,' | ',place6,' ');
      writeln('     |   |   ');
      writeln('  ---+---+---');
      writeln('     |   |   ');
      writeln('   ',place7,' | ',place8,' | ',place9,' ');
      writeln('     |   |   ');
      writeln;
     writeln('Sorry, nobody won this game.');
     points := points + 0;
     lastwinner := lastwinner;
     goto playagain;

     playagain:
     writeln;
     writeln('Would you like to play again? Y or 1 for Yes, N or 0 (zero) for No.');
     read(ynagain);
     if ((ynagain = 'Y') or (ynagain = 'y') or (ynagain = '1')) then goto begingame else goto endgame;

     illegalmove:
     writeln('Sorry, that''s an illegal move.');
     goto picknumber;

     compcrash:
     writeln('Ekk! The computer went crazy and started shooting! You died...');
     points := points - 1;
     goto playagain;

     endgame:
     writeln('Your ending points were: ',points);
     writeln('Press Enter or Return to quit');
     readln;
end.

Tags:

Categories: article, software

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Dead? The digital download is barely out of its teens

Yesterday Slate posted an article by Farhad Manjoo titled The Digital Download Is Dead: How Google's music-streaming venture will change the gadget and entertainment worlds forever.

After first, rightly, attacking Apple's iTunes and iPod (and related) platforms as being slow and unwieldy, especially on the predominate operating system Windows (not even mentioning Linux), and overall behind on the times, Farhad moves us from syncing our music collections out to the cloud. Which isn't much of a surprise given that, despite some rather large issues, the cloud has been 'in' for a couple of years now. But even more surprising Farhad argues at the end of the article that "[i]n the future, not only will you not get a CD when you buy an album, you won't even get a digital file."

But there's an elephant in the room. A rather large one, taking up every available inch of space. Namely the global music industry.

At the moment I'm listening to X Japan. If I do a search for this band I find the following:

  • Amazon MP3: Two albums available - Blue Blood and Jealousy.
  • Amazon music: 236 results, seemingly with most of their releases covered (but I wasn't about to page through all those results). Of special note is the magical word 'Import' next to the majority of the albums.
  • iTunes: Same two albums as Amazon MP3 and the I.V. Single.

There's better examples, I just happened to be listening to X Japan at the moment. Go ahead and look up some popular European bands and see if you can find their music on Amazon or iTunes, or any one of the other online sellers of music (for the United States). Chances are you'll find a good deal of music that you can't purchase, unless you're willing to pay import prices for a physical CD.

Now with this in mind, Farhad expects physical media to disappear, in the future. In lieu of an extremely ambigious timeframe, let's substitute that with 'in the next 5 years' or 'in the next decade.' With the music industry as slow as it is, do we expect not only for the industry to move to the cloud, but to also deal with the 'import' situtation in a respectable way?

Instead of moving away from digital downloads, which by the way work better (for me) than a cloud service - and service it will be, with the associated recurring costs - I'd much rather the industry finish show that they're willing to embrace digital media and its promise. As things stand now they haven't embraced digital media, and won't until everything (give or take) that's available in physical form is available digitally.

Now if you want to move to the cloud at that point, or alongside the expansion of digital downloads, fine. Go right ahead. Other groups have certainly tried, but until the global market elephant is removed from the room, any new services will run into the exact same issue.

And until we see 'foreign' music available digitally to 'all,' please don't suggest we get rid of physical media, or the issues now will just get pushed to the cloud.

Side note: the gaming industry

A similar debate is going on in the gaming industry. Digital downloads of games is finally becoming more and more prevelant, not only with DLC, but the making of 'classic' games available for purchase and download, whether that be through the Playstation Store, Xbox Live, or Good Old Games (GOG.com). They too are looking at cloud-based services, but they too have an issue with imports.

Progress is moving forward, not stepping to the side, and until the promise of digital media/downloads is embraced, anything based on it will suffer the same issues.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Netflix on the Wii - my experience

After receiving my instant streaming disc for the Wii a long while back, I finally popped it in my Wii and gave it a try.

For this experiment I watched three episodes of 30 Rock: Season 1. I wasn't expecting much for quality, and each episode isn't very long, so I thought I was giving the Wii a very good chance.

Overall, I was extremely impressed in the entire experience, and definitely think Nintendo's own video channels can learn a lot.

Unlike on the PS3 and Xbox 360, most of the functionality to browse and watch videos is available right from the control, with on-screen cues. For example, to start watching a video, press '1.' However, I didn't pause the videos, and am not exactly sure how that would be done (but assume the A button).

The quality of the videos was much better than I expected, with TV-quality picture and sound. I do have a widescreen television (Sony Bravia) and while most content on the Wii displays in a standard-sized box, I had to manually switch to widescreen to view the video as expected, but since I have to do that for everything but the Xbox Netflix experience, I was expecting that.

Unfortunately, since the Wii's control is the only console that I have that doesn't offer a rechargeable solution, I probably will not watch another Netflix streaming video on it. If it was my own choice to watch Netflix streaming videos on my television, however, I absolutely would.

Nice job Netflix.

Tags: ,

Categories: article