Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Win32 development

by dragonchild (Archbishop)
on Dec 03, 2005 at 23:12 UTC ( [id://513869]=perlquestion: print w/replies, xml ) Need Help??

dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

I want to write a Sudoku puzzle generator (similar in look'n'feel to Minesweeper) for my father for Christmas. He's on Win32, so I need to write something that feels like Minesweeper. Problem is that I don't know squat about Win32 programming, GUI development, and/or Win32 packaging/installation.

So, here's what I'm looking for:

  • What's the easiest and quickest solution to build a nice Minesweeper-like game?
  • What's the easiest and simplest way to package said game? I want it to install into the Games folder, just like it's Minesweeper.
For the first, I'm looking for ease of development. For the second, I'm looking for ease of installation.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re: Win32 development
by polettix (Vicar) on Dec 04, 2005 at 01:23 UTC
    I wrote a little SuDoKu player and I posted it in the code section here. It uses Tk, which is included in ActiveState distribution. Note that it does not include a puzzle generator, something that does not need a GUI :)

    In win32, I associated the .plw extension to the execution with the wperl.exe program, which is basically Perl without a console. Then, you can save the game with the .plw extension, and create a link inside the "Games" menu.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: Win32 development
by davidrw (Prior) on Dec 04, 2005 at 02:23 UTC
    You can use Tk so that you can develop it on any platform .. as for distributing, PAR makes it easy (from a windows box; i think cross-compile is possible too) to bundle into a .exe .. as for installing it, you could just write a batch file to drop it into the right place, or even a perl script to to it (and Win32::Shortcut to put a shortcut in the accessories/games folder or desktop)

      If you want to use activestate perl, tk and PAR together, use ActivestatePerl 809 with the included Tk. Later Perl builts seem to have problems with the combination of Tk/PAR... you can pack it, but if you want to execute the .exe archive, there arise some ugly errormessages.

      If you need instruction for tk-mines from my homepage in english, just send me an email or msg. (for a link see esskar's posting above...)

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      Do you have an example for using each of these items? I have 3 weeks to write this and I know nothing about the Win32 infrastructure. I've also never used Tk, PAR, or any of these other tools. I'm a webapps/DBA guy who lives completely on *nix. Help me out, brother!

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        PAR is the easy part .. get v.90 by running ppm3 from a DOS prompt, and then doing:
        install http://www.bribes.org/perl/ppm/PAR.ppd
        That gives you a script pp to run...
        pp -o foo.exe --gui foo.pl
        And that's (probably) it -- you have a foo.exe you can drop anywhere (and no pre-existing perl.exe or modules required on the target machine)..

        As for Tk, This thread was just posted Tk how-to? and has some good stuff.. but i'd definitely go the route of finding some examples -- esskar's line to Tk-mines sounds promising..

        I haven't actually used Win32::Shortcut, but i've seen PM postings about it in the past 6 months..
Re: Win32 development
by esskar (Deacon) on Dec 04, 2005 at 02:10 UTC
Re: Win32 development
by PerlingTheUK (Hermit) on Dec 04, 2005 at 03:05 UTC
    Dragonchild,
    I think the Win32::GUI::XMLBuilder is what you look for. Though I am not sure if you really want to use Buttons (as in Mine Sweeper for the SuDoku fields. Alternatively Tk is running fine on XP (the only one I ever had to use but I doubt there are problems with other Win32 versions.) And it keeps you platform independent.
    I have been packaging my Windows applications with Activestate's PerlApp. This costs a bit but is the easiest to use. However if you try the testlicence be aware that all Windows binaries will not run after the test period has expired.
    For your criteria: I have used the above all under Win32 and it worked without any trouble. For someone to come in and make a change is solely depending on your coding I guess. All this is based on the assumption you are developing on a Win32 machine.

    Cheers,
    PerlingTheUK
Re: Win32 development
by BrowserUk (Patriarch) on Dec 04, 2005 at 04:25 UTC

    Are you looking to write?

    • A puzzle generator.

      You could consider using LWP to pull pregenerated puzzles off the web.

    • A solver.

      I never quite cottoned to the point (beyond the programming challenge) of solver programs? Doesn't having a program that solves the puzzle rather defeat the purpose of doing the puzzle?

    • A solving assistant.

      What features, beyond verifying that you haven't violated the basic rules of the puzzle, would you like to add to such a program?

    If you are going to do the installation, is it much harder to do a Perl install at the same time? Of course, once one family member has a copy, they'll no doubt want to share it with others, which I guess is where a PAR wrapped version would be useful.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I want to do a puzzle generator that, basically, starts with an empty board and randomly inserts a number. It does this until it can solve the puzzle. Then, it presents the puzzle to the player. Depending on settings, it can also provide hints to the player because it already has the solution.

      My Dad will be here for Christmas, so I could punt on the installation stuff because I can install it by hand on his laptop, but I was hoping to use this as a learning exercise. I suppose that just doing the Tk would be enough of a learning experience ...


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

        The best Sudoku puzzles are written by humans. Computer Sudoku generators still have to be relatively sophisticated in order to achieve a target level of playability. The easiest Sudoku puzzles are rediculously simple, and the hardest literally require branch investigation down possibly multiple branches for a number of levels before the person solving the puzzle can determine which branch is going to play out to the end. In fact, some can be rendered unsolvable without resorting to guessing. Puzzles generated at random are going to sometimes be unsolvable unless a person gets out a pen and paper and starts making assumptions (guesses) and pursuing branches until they can be proven to not be a viable solution. In fact, in the worst cases, it may be impossble to take a set of 'givens' to the point of eliminating all but one solution.

        Part of the problem is in deciding what shall be the 'givens'. The givens have to be chosen in such a way as to make a puzzle solvable without pure guessing. In other words, they should set up a relationship that can only lead to one unique solution.

        The Wikipedia contributors have done a better job than I'm doing of explaining my point, and their eplanation can be read at http://en.wikipedia.org/wiki/Sudoku. In particular, the discussion of construction should be of interest. Of course you're a bright individual, and I wouldn't put it past you to develop a very well thought-out implementation. I just wanted to contribute a few caviets that might help you toward creating a more refined gadget.

        Good luck! I'd love to see the outcome.


        Dave

Re: Win32 development
by spurperl (Priest) on Dec 04, 2005 at 17:17 UTC
    dragonchild,

    I've written an almost exact reproduction of Minesweeper (look-n-feel wise) in Perl using the Tk GUI toolkit. The code is simple and well-documented, and the program works perfectly on Win32. You can download it from here. It will show you how to use Tk's Canvas to achieve what you want.

    Package / install - wise, it's even simpler. The excellent PAR module has a "pp" program in it that creates executables (complete, self contained Win32 .exes) from your scripts, including all the dependencies (like Tk). A GUI application with Tk will weigh around 2.5MB, will take a few seconds to load the first time it's run (it unpackages stuff to the Temp directory) and then run almost instantly.

Re: Win32 development
by Moron (Curate) on Dec 05, 2005 at 09:56 UTC
    For a serious project I would indeed use Tk like about everyone else. But for a one-off for Windows, as much as, professionally, I puke blood while saying it, I would expect get a quick and dirty solution using (cringe) Visual Basic (...cowers in corner).

    Update: Perhaps I should explain why. Whereas both Visual Basic and Tk are event driven, Tk doesn't have a form painter which creates start-up overheads that VB can initially avoid. A form painter gives initial benefits because of the stronger encapsulation of data, but VB, Centura and so on are unsuitable for serious projects because that same strongly visual encapsulation also means the code becomes decreasingly manageable over the longer term. Which is only not a problem if there is a fixed project lifetime of less than about a month.

    -M

    Free your mind

Re: Win32 development
by rokadave (Sexton) on Dec 05, 2005 at 02:53 UTC
Re: Win32 development
by mattr (Curate) on Dec 06, 2005 at 07:27 UTC
    I've been using wxperl and have not in fact used Tk. Wx has a gridbagsizer that might be useful, um anyway I'm curious why everyone thinks Tk is the obvious WTDI.

    Matt

      One reason might be that when you download the documentation, you find such gems as:

      • Under "Programming strategies" - "Strategies for reducing programming errors":

        Use ASSERT

        Although I haven't done this myself within wxWidgets, it is good practice to use ASSERT statements liberally,...

      • Under "Programming strategies" - "Strategies for debugging":

        Positive thinking It is common to blow up the problem in one's imagination, so that it seems to threaten weeks, months or even years of work....

      • Under "Topics overview" - "wxWidgets Hello World sample"
        // // file name: hworld.cpp // // purpose: wxWidgets "Hello world" // // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif
      • Under "Topics overview" other subheads include "wxPython overview" & "Archive formats such as zip", but not a single mention of Perl or wxPerl.

        Even the contents page header is "wxWidgets 2.6.1: A portable C++ and Python GUI toolkit"

      • The first mention of Perl I found was under "Classes by category" - "wxTopLevelWindow" - "wxTopLevelWindow::GetIcon" where if found:
        • wxTopLevelWindow::GetIcon - wxPerl note: This method is not implemented in wxPerl
        • wxTopLevelWindow::GetIcons - wxPerl note: This method is not implemented in wxPerl
        • wxTopLevelWindow::GetTitle - wxPerl note: This method is not implemented in wxPerl
        • ...

      At which point I decided whatever limitations of documentation Tk has, and they are myriad, at least most of it is a) relevant; b) mostly Perl related.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Hello, thanks for your considered reply. I'm not the wxPerl expert but I've done a project or two in it. I think with all respect that you've gotten behind the wrong side of the axe. Specifically, you are reading the docs for the C++ libraries which are wrapped by wxPerl. You do not program in C, you program in Perl.

        There is no ASSERT needed in Perl of course, in fact I don't remember that line at all to tell you the truth. Maybe it is needed to stay sane in C++ programming with wxwidgets, but I have no experience doing that myself. It's easy to debug wxPerl since it's perl and you have stderr output on the console too, plus a logging module. You suggest wxwidgets is immature but a glance at wxwidgets.org shows that is untrue, in fact lots of neat cross-platform C++ projects (like Xara for instance) use it.

        It is true that not every single routine has been wrapped, but the critical mass has been way exceeded IMHO. There is a very active mailing list and in fact there are some extra perl functions added while some duplicate C functions are not. There are also some which were skipped as not seeming important. When people find them important, so far as I can see it gets wrapped extremely fast.

        The wxwidgets C++ libraries are also a moving target and advancing/growing very quickly. This is a good thing. I do in fact use the C++ manual when seriously programming wxPerl, since it is extremely useful. There are also a lot of third party C++ modules in the contributed code section, and I wouldn't mind seeing some of those wrapped too. Perhaps lack of a wrapped video contributed module is significant I think though there is ActiveX.. anyway it is available for wrapping. The wxperl wrapping of wxwidgets is in general quite useful and has struck me as being more interesting than Tk though I would like someone with much experience in both to weightin on that. Also I wonder if sdl-perl and gtk-perl are faster, since I remember a neat game (sdl perl I think) called Frozen Bubble. I wonder if it is doable in wxPerl yet. (It uses Ogg Vorbis). I'd like to see it easy to do animation and multimedia scripting in perl, in wxPerl. And being a lazy perl programmer in a good sense (I think) I'd like to see it even easier to make apps than it is now. (It's easy but you still have to tell the computer what to do.)

        As for the example you note, I just checked the manual (for wxwidgets 2.6.2) and your post appears to be already obsolete. There is no wxPerl note as you mention for the three subroutines you note. And I built a wxPerl app with custom icon and title (true I was setting not getting) nearly a year ago.

        In conclusion I have to say that while I greatly respect your posts in all other areas I really think it is time to take another look at wxPerl. In particular, look at the wxPerl demo.pl application which shows you the source code for each window as you demo different functions, it is eye-opening. There are already a lot of users but I would like to see twice as many and it seems the barrier to that is impressions similar to yours.

        WxPerl will of course continue to grow, I hope, and I would not mind seeing it get easier and easier. Currently I think it does a very good job of letting you override all widgets and window types to make your own custom reusable widgets and windows as packages which can be added to CPAN. Anyway, slide over to wxperl.sf.net and see what the fuss is about!

        Cheers, Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://513869]
Approved by friedo
Front-paged by Errto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-18 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found