games

Thực ra viết con game để chơi là phụ, chính yếu vẫn là muốn thử nghiệm các kỹ thuật khác nhau với “lambda function – anonymous function – hàm không tên”!

ự viết con game Solitaire này mấy năm trước, nhưng lười, không bỏ lên AppStore. Game mà tôi tự viết để tự chơi thì cũng khá nhiều, viết vì kiếm không được game tương tự đúng ý, cái thì quảng cáo quá nhiều, cái thì đồ hoạ quá xấu, cái thì nặng nề, tốc độ quá chậm, chạy không mượt, mà tôi chơi Solitaire, mấy ngón tay bấm liên hồi như đánh piano vậy! Trò Solitaire chuẩn chơi trên máy Windows tối đa chỉ 24K điểm, nhưng cầm cái iPad mà chơi thì trên 30K điểm là chuyện thường! 🙂 Game này viết chỉ một source code, chạy trên tất cả các nền Apple (Mac, iPhone, iPad…), làm cái engine sẵn, đọc game rules từ file lên, hiện tại hỗ trợ đến 99 biến thể (variant) Solitaire khác nhau!

Nhớ lại đợt Sài Gòn giãn cách XH vì Covid-19, suốt ngày chỉ có chơi game giải trí, hoặc làm mộc, cưa bào, đục đẽo để vận động tay chân! Nói về chơi game, căn bản đó không phải là chuyện gì xấu, nhưng tôi thường chỉ chơi game logic đơn giản, mỗi ngày chơi 15 ~ 30 phút tối đa, không chơi các game có kịch bản hay những game mất quá nhiều thời gian! Tác hại của game đối với giới trẻ không cần phải nói, nhưng lỗi không nằm ở game, lỗi ở xã hội và giáo dục, tạo ra cho chúng nó một môi trường nghèo nàn, một tâm hồn trống rỗng, như cái lỗ đen sâu hoắm, nên ngoài những thứ vớ vẩn, nhảm nhí ra, chúng nó không còn biết điều gì khác, riết rồi thành thần kinh, bệnh hoạn và tệ nạn! 😢

thò lò

ông cụ hiện đại khiến cho ai cũng có thể trở thành “nhà ngôn ngữ học”, đôi khi cũng muốn tập làm một “cụ An Chi”, người phụ trách chuyên mục “Chuyện đông chuyện tây” trên bán nguyệt san “Kiến thức ngày nay” một thời đã khá xa xưa 😀. “Thò lò” – 陀螺, âm Hán Việt đọc là “đà loa”, “đà” tức là quán tính, “loa” là con ốc.

Để rõ hơn, mở trang translate . google . com, nhập 陀螺 và bấm nút phát âm, nghe hầu như là giống âm Việt “thò lò”. Vậy đã rõ “thò lò” trong thành ngữ “quay tít thò lò” nghĩa làm sao (con quay, con vụ). Và cũng có thể đoán thêm, từ này du nhập VN mới sau này, nên âm đọc của nó gần với âm Bắc Kinh hiện đại hơn là âm Hán Việt cổ!

7554 – the điện biên phủ game

game to be published this October, to be precise, the first Vietnamese FPS (first person shooter) 3D game, and you know what it’s about, the famous Battle of Điện Biên Phủ. The game features 4 main characters, all joined the anti – colonial – French movements from the very early days, participated in various operations before arriving at the final confrontation at Điện Biên Phủ. Not yet to be released, but below are some nice preview screenshots. Having some experiences with game engines, I could say that PC 3D games nowadays are not that hard as before.

They are not really about low level graphics techniques, you would rarely even touch to OpenGL (or DirectX), the engines support most elements you would need. To make a game interesting, it is more about storyboard, scene building, animation, physical modeling and game AI. Anyhow, this is an interesting and promising project, since not only it’s the 1st real FPS game made in Vietnam, but also the first game that takes its inspirations and stories from our history!

verlet integration

little fun with gaming physic, written using Three.js, the 3D library built ontop of HTML5 and WebGL. Physics engines like ODE or PhysX support a wide range of simulation: rigid body, soft body objects… While those engines are powerful, they are somewhat weak in scalability, e.g: to simulate the flag below, we need to create an array of hundreds of objects, which may not really feasible on small devices.

This demo tries its own physical calculation called Verlet integration: numerical method to apply Newton’s second law of motion to a system of point masses. Verlet integration, despite its complicated formal description, is simple enough to be calculated and executed in real time on the low end mobile devices.

The demo works best on Chrome but it should work on any browser that supports <canvas> (try dragging the flag to add some motion).

game terrain



little technique to create terrains for use in game. Sometimes, we need to create game spaces with: mountain, plain, valley, river… the environment where our game scenes take place. It could be a labour – intensive task unless we can make use of the existing geographic data. Some games like Flight Simulator have the scenes modelled exactly after the real world.

First, we would need a topographic map, typically the height – contour map used in artillery. Nowadays, the SRTM and ASTER GDEM projects provide these data for free in digital format. They are satellite (radar) images of the earth surface with resolution upto 90m for SRTM and 30m for ASTER GDEM. I would recommend the ASTER GDEM for its higher resolution. Go to the site, follow its complicated registration process to download the data via NASA’s ftp server.

The downloaded data would be Zip packages with height info in GeoTIFF format. Next, we would use this MicroDem utility to convert it into PGM, an intermediate format that can be read by Photoshop (or GIMP). Then we save it as heightmap (PNG or TIFF format) which can be imported into most game editors. By now, the terrains are recreated exactly as they appear in our real geographical world. Just apply textures, lighting, water and other stuffs then to make it look good!

Images on the left: 1. topographic data as rendered by MicroDem, 2. heightmap (grayscale image) as viewed by Photoshop, 3. the terrain created and roughly decorated (a low – poly version), here is the Sơn Trà peninsula (or les vallées de mon coeur 😀), the shape, the silhuette that’s long been in my heart!

goswf

great tool to learn Go (weiqi): goswf, so nice the flash board game! You could learn the moves as well as view comments on each move! Below is Game of the Century, the famous game between the legendary Go Seigen (black) and Honinbo Shusai (white), head of the Nihonkiin (日本棋院 – Nhật Bản kỳ viện – The Japanese Go Institute) at the time. The game lasted for 3 months, please note the 160th, the white’s ingenious move! There are thick books on this game, but there’s never been any simple comments on it!

elektronika

Russian Elektronika clone

Nintendo Game & Watch original.

very sweet souvenir, a sudden reminiscence that happen to recall, my first computer game. Some day in the mid-80s, I’d got a gift, a Soviet built, hand-held device. I still remember the sound, the addictive feelings came with it! The game featured a wolf, a rabbit, likely to be seen in the Nu, pogodi! cartoon series (pronounced by us – little child as nupacachi). The game’s goal is trying to catch falling eggs, if an egg missed, it breaks and a chick is born. If 4 chicks are born, you lose! I played hundreds of games on this pad, then batteries ran out but can’t find anywhere replacement back then 😢.

Several years later, in the late-80s, these types of games became obsolete, then seen the Nintendo’s Famicom console widespread. Now I know it was a clone of Egg (a variant of Mickey Mouse), played on console manufactured by Nintendo. Although capable of building super computers, the Soviet Union was, at the time, in shortage of consumer goods, they choose to reverse engineer various Western products.

It’s very interesting to learn about separate branches of electronics and computer science in the USSR. They had distinctive type of computers, architectures, operating systems, programming languages… Some are even found nowadays quite bizarre like the trinary computers (as apposed to binary systems we’re extensively using). It should be noticed that the Russian had very successful specific-purpose models that offer superior power in narrow fields (such as ballistic computing). Areas in their separated genealogical branches of science and technology remain mysterious until today, some are covered in the book Computing in Russia, a highly-recommended reading!

Update, May, 13rd, 2009

It was kind of a very first and famous game, yet only ones at the time know about it, in the early and mid 80s. After searching a while, I found various simulators for playing the Game & Watch series, on Linux, on Windows and even on Mac. On the left is Flash version of the game, the Soviet variant named Nu, pogodi!, you can guess from Cyrillic letters above the screen. Enjoy!

ô ăn quan

Có 50 quân dân, và 2 quân quan, mỗi quan tương đương 10 dân. Người chơi có quyền chọn di chuyển theo hướng bất kỳ, những game Mancala khác chỉ được di chuyển theo một chiều nhất định.

Ăn quân ở ô kế tiếp trong lượt đi chứ không phải ở ô đối diện của đối phương. Khi đến lượt mình mà không còn quân để đi thì phải bỏ 5 quân đã ăn được vào 5 ô của mình để tiếp tục chơi. Trường hợp không có đủ 5 quân thì phải vay của đối phương và trả lại khi trò chơi kết thúc.

rò chơi dân gian Việt Nam Ô ăn quan thuộc họ Mancala, có nguồn gốc châu Phi và có hàng chục biến thể khác nhau trên thế giới. Khi nhỏ, tôi có chơi trò này vài lần, gọi theo tên địa phương là Ô làng chứ không phải Ô ăn quan. Hôm nay thử nhìn cái game này dưới góc độ tin học xem sao! Ô ăn quan có một số luật khác với những game Mancala khác.

Những luật bên, nhất là luật thêm & mượn quân làm Ô ăn quan phức tạp hơn nhiều so với những biến thể Mancala khác. Viết một chương trình cho máy tính chơi Ô ăn quan không phải là quá dễ dàng, dùng những heuristic đơn giản (hill-climbing, min-max, hay brute-force đến một độ sâu nhất định…) không đủ bảo đảm máy tính sẽ thắng trong nhiều trường hợp.

Trên internet, tôi không tìm được game Ô ăn quan nào theo đúng luật Việt Nam. Một số là những biến thể gần giống Ô ăn quan, một số tác giả claim là đã viết Ô ăn quan nhưng không cung cấp được link download. Có vẻ như game này không dể như khi vừa mới nghĩ đến! Bạn nào có ý kiến về chiến thuật chơi game này xin được trao đổi để cùng phát triển một trò chơi hoàn chỉnh.

Bên đây là screenshot của một Java applet tôi vừa viết trong vài tiếng đồng hồ, cho phép 2 người chơi với nhau (máy tính chỉ kiểm luật, chưa phải là một chương trình cho máy tính chơi thực sự). Những hiệu ứng đồ họa: di chuyển quân, ăn quân nhìn rất giống thật, graphics được vẽ bằng Photoshop: những viên sỏi và bàn chơi được vẽ bằng phấn trên mặt sân xi-măng… gợi lại những kỷ niệm thủa nhỏ.

minesweeper

wo more hours of work and I’ve added this hexagonal tiles to my MineSweeper! Anyone interested in the game can found the tiny binary and source code (450 LOC) here. Mine sweeping with hexagons is quite a different experience! More about MineSweeper, a simple game?

On the left: Minesweeper with hexagonal tiles

virtualization

MineSweeper running in DOSBox

Click the demo page below (jpcapplet.jar – 1.8 MB in size), it would take some times to load, embedded in it is a DOS image (floppy.img) of a floppy’s size (1.4 MB). In Linux, using dd to create a blank image file, launch JPC app, mount the empty image, fdisk to give it a partition structure, format to give it a bootable FAT12 file system, copy the files over, edit autoexec.bat to have the game run at startup, and voila – there you are, the classic DOS game of MineSweeper on the web!

eside is screen-shot of my very first programming, the classic MineSweeper, an exercise I did first year at university. After getting started with Borland C++ 3.1, I began to write numerous toys like this; small games, graphics, animation, 3D… are among the things I was very fond of. We still had not had Internet in Vietnam then, lacking of information, we’d reinvented many wheels, including a package for displaying 3D objects (in form of polygon mess), a complete GUI for DOS with window, menu, toolbar, all kinds of controls: combo, list, button… But as they say: don’t reinvent the wheel, unless you plan on learning more about wheels, the reason we did all that fun stuff.

Back to my MineSweeper, it’s tiny, about 350 LOC (Line Of Code), using BGI (Borland Graphics Interface), C/C++ and some ASM. Yesterday, just want to check the old source, but didn’t have a Windows machine at hand, I needed to run the Borland C++ 3.1 compiler on my Linux box. Wine is good for many Windows applications, but it simply won’t work with pure DOS programs. Then I found DOSBox, you start it up in form of a console, mount a directory in local file system, have BC 3.1 installed and compiles flawlessly, and MineSweeper runs well on this virtual DOS on top of Linux!

That’s some layers of virtualization, say I want more, I want to show MineSweeper on the web, but don’t want to make change to the code, or even to the compiled binary. Could it be possible? The answer is: YES! You would need JPC, a pure Java IBM-PC emulator, it runs where there is Java: x86, RISC, mobile phone… On top of it, you can run a bundle of different OS: DOS, Linux, Windows… Then comes the delicate distinction between virtualization and emulation, hardwares, softwares, all can be virtualized to some great extent. Imagine you would run some games & utilities on a virtual DOS (or Linux) running inside JPC, hosted in Firefox browser, which in turn runs on Windows (or Linux)!

JPC can only bring about 20% power of the native machine, and even a tiny game like this is overkill to it, and mouse functioning is really crappy too. But that’s suffice to demonstrate the idea, JPC could be improved I believe. More games would be added to this Web DOS console later on! Anyone still remember Tetris, Croix-Zero, Snake, Mario…? So, what’s the points for JPC? Demonstrating the fractal principles in hardware, software evolution? Too much “nostalgia” for the “good old days” – DOS games? Anything else or just reinventing the wheel? The answer may be so, but I love this idea of cultivating the past, and pop out new things for the future!