2048

11 Apr

Afternoon app – 2048

You may or may have not heard about a popular new game called 2048

We have some very exciting new work in our development builds, a new source code editor, which I wanted to exercise. 

Around the same time, I saw the article linked above about the game 2048.  It is a simple four by four grid with numbers that you slide around, trying to add them up to …… 2048!

Image

I downloaded a free version of 2048 onto my iPhone, and there is also browser based version here. I checked it out and it looked pretty interesting, so I decided to implement a simple version of it as an “afternoon app”.  An Afternoon app is a simple time-boxed implementation.  Since Smalltalk lets you do a lot in a short amount of time, it is a great choice.

I built it and published it on the public repository.  You can find it as TwentyFortyEight.

It is an MVC designed app with these three classes.

TwentyFortyEightApp

TwentyFortyEightModel

TwentyFortyEightView

 I reverse engineered it by observation.  I tried a couple simple ways to process the moves, then refined them.    My #process:  method takes an array of the four items in a row or column, and looks like this:

process: array

               “process an array of the grid”

               self compress: array.

               self combine: array.

               self compress: array.

               ^array

 #compress:         slides the elements down to the far end of the array.

#combine:           adds adjacent cells of the same number, one pass

 The second compress is required in situations where there are two combines in the one pass.

 Since you can move four directions, up, down, left, right, it gives #process the row or column for right, down respectively.  For left and up it reverses the array for #process, and then flips it back for integration into the grid.

 I made an assumption which turned out to process incorrectly in some circumstances.  Rather than fix it, I left it as a challenge to find (not too hard, not to trivial) and change for those who want to tinker with the application.   There is another needed fix (hint: the new value that appears) which is a very easy fix.

 How can the implementation be improved?  Other than the needed fix mentioned above, the application does not detect when the game is over, or allow you to restart it. 

 A big improvement that would take some more time would be to add animation.  This would probably require model changes to communicate in terms of the moves in order for the view to animate them. Visually, adding animation would be a big improvement.  I welcome any developers to give it a try and share their results.  I may give it a shot myself.

 What else could you do?  You could try using different algorithms for auto-playing the game, in order to discover or test heuristics in order to maximize your score.

 If you have any more ideas or any questions, I would be happy to hear from you.  Reach me at the email below.

 Best Regards and happy Smalltalking!

 Arden Thomas

athomas@cincom.com

Cincom Smalltalk Product Manager

Advertisements

Launching VisualWorks

23 Oct

Launching VisualWorks

There are multiple ways of starting your Smalltalk image, some you may not be aware of, but would find useful.  This is primarily for developers who have more than 1 version of VisualWorks installed on their system.   Configuration files make it easy to manage and run images from multiple versions.

The basic ways to start an image;

1)      The “Standard” way

2)      VisualWorks-1.15 (preview)

3)      Launchpad

 

1)      First the Standard way.

On Windows, .im extensions are associated with VisualWorks.exe.  The VisualWorks.ini file (found in the same directory as the .exe) contains the image signature, which identifies the version of the image and the full path and vm to run it.  Normally you edit the .ini file to reflect your installation.

So an entry might look like:

77 01 c:\Program Files\Cincom\vw7.7.1\bin\win\vwnt.exe

Launching a 64 bit image is accommodated too:

79 128 c:\Program Files (x86)\Cincom\vw7.9\bin\win64\vwnt.exe

You provide an entry for each version of VisualWorks installed, or even an entry for each version of image you may be using.  You can usually use newer VM’s on older images within the major family.

2)      VisualWorks-1.15

This variant can be found in the preview/bin directory on Windows platforms.  This is especially useful if you are a VWDev participant and need to distinguish between versions at a finer granularity.  Note that you can find the VisualWorks-1.15 functionality on OSX & Unix platforms as VisualWorks.sh in the preview/bin directory

The differences are:

  • A more detailed signature
  • Specification of the home directory as well as the correct VM

(the second parameter after the “?” is used to set the VISUALWORKS variable)

An entry in this ini file looks like: (each entry all on one line)

79 0 0 0 C:\Program Files (x86)\Cincom\vw7.9\bin\win\visual.exe?C:\Program Files (x86)\Cincom\vw7.9

 

79 128 0 0 C:\Program Files (x86)\Cincom\vw7.9\bin\win64\visual.exe?C:\Program Files (x86)\Cincom\vw7.9

 

The last two numbers in the signature are used in identifying interim builds, as in the weekly builds in the developer program.  So some recent build entries I have looks like this:

79 0 20 4 S:\Cincom\vw7.10\bin\win\visual.exe?S:\Cincom\vw7.10

79 128 21 4 S:\Cincom\vw7.10\bin\win64\visual.exe?S:\Cincom\vw7.10

79 0 04 4 S:\Cincom\vw7.9.1\bin\win\visual.exe?S:\Cincom\vw7.9.1

79 129 04 4 S:\Cincom\vw7.9.1\bin\win64\visual.exe?S:\Cincom\vw7.9.1

This is useful for making sure you are running the exact new vm along with the development build. This is what I am using currently for testing our weekly development builds.

 

3)      A third way to start an image is with the VisualWorks Launchpad.  The Launchpad is a very useful application that lets you create and name images (32 or 64 bit), and also store them in the proper manner on Windows and OSX (a directory in a read-write area).  The icon to start the Launchpad gets installed on your desktop, so it is easy to find, and it makes it simple to find and create new images.  The Launchpad will evolve to be even more useful for configuring and creating images.  The Launchpad also has a configuration file, and is rather capable, flexible and configurable.  A development engineer is working on an article describing this, so I will not delve into it here.

 

I hope this article gave you some ideas on how to more effectively start and use VisualWorks.  Questions?  Please send them to me at: athomas@cincom.com

Regards

Arden Thomas

Cincom Smalltalk Product manager development tip

5 Sep

Cincom Smalltalk Product manager development tip:

By Arden Thomas, Cincom Smalltalk Product Manager

Often developers get into a flow and habit of how they use their tools.  This is good since as a developer becomes familiar with a tool, they also become more productive.

One potential drawback to this familiarity is that we may not seek out and utilize, or even realize, product changes that may help us form new and better workflows.

Product improvements to our Smalltalk products keep coming – we are consistently improving the products in one way or another.

With this in mind I want to make note of changes that may be overlooked but possibly very valuable for developers.

We are probably all familiar with tabbed internet browsers – and the advantages they give us.  Namely, they allow us to have one browser open with a dozen tabs, rather than a dozen individual browser windows open.

An often heard issue in Smalltalk is the problem of having too many windows open.  I still get asked about this fairly regularly.  You can combat this issue – you may know of the browser extension RBTabbedToolset that gives you a tabbed browser, which is very useful.

But did you know multiple browsers in one window is built into the base product?  It is not necessarily obvious, which is why I am telling you about it.  If you open a system browser and click on the “View” menu, it looks like this:

“New View” or Shift+Ctrl+B (B for Browser) gives you another browser in the same window!  But how do you navigate without tabs?  Alt-n, where n is the number of the browser you want, allows navigation between the windows.  Also, returning to the view menu allows you to navigate.

If you want tabbed navigation to these multiple browsers, load the RBTabbedToolset extensions.

Base Browser

Browser with RBTabbedToolset loaded, and second browser created:

So to recap:

  • Shift+Ctrl+B to add a new browser in the same window.
  • Alt+n to navigate to the nth browser.
  • RBTabbedToolset to add tabs for easier and obvious naviagation

Hello world!

20 Oct

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can always preview any post or edit it before you share it to the world.