Posts tagged: programming

MonoGame, XNA and Documentation Hell

2000px-MonoGame_Logo.svgI confess I have some admiration towards the Mono Project. It is the base of different tools, and it allows those tools to run virtually on any device. A good example is the Unity 3D Game Engine.

In my teaching duties this year I need to each MonoGame. Not sure if this is a good choice or not, I just needed to keep with the old syllabus as I did not have any time to prepare the course as I should.

In case you are not aware, MonoGame is Microsoft XNA made public. Although the libraries, themselves, are easy to install under Windows, the most recent version is not available for Mac or Linux. The documentation that is available is mostly from the old XNA, in Microsoft MSDN. There are a few mini tutorials and blog posts that help on some specific details, but there isn’t a official, well prepared, source of documentation, and that is a shame.

Another problem from basing things on Microsoft previous work, is that MonoGame depends on Windows libraries, some of which are not free, and can’t be made available by the MonoGame project, meaning the developer needs to go through a list of old software (yeah, from 2011 is old software) to be able to have everything working.

One of the problems with MonoGame is that it depends on a binary format, named XNB, for importing assets. I am not sure if this format is open or not, but given it is Microsoft, I do not think so. To create these files, from other files, like image or sound files, you need a tool to convert. It seems (although I did not test yet) there is such a tool for Linux and Mac (the MonoGame Pipeline) but not for windows (are you sensing the strangeness here? the latest version of the library is only available for Windows, but the needed tools are not available for Windows…).

I wasted 5 hours trying to figure out how to create a XNB file from a WAV/MP3 file. I searched for tutorials, I downloaded software, I tried different approaches. None works with Windows 8.1 and Visual Studio 2013. I still did not try to contact the MonoGame team or foruns. But given this is something crucial for game development, I can’t understand how there isn’t an official reference from the project, on how to create these files).

The most promising tool I found was XNBBuilder (also known as XNBFormatter), a standalone tool for this conversion. But, from standalone it has few. It depends on XNA libraries (that I have installed) and, even with those libraries available, it still complains on them missing. In fact, a book I bought from Apress about C# game programming in MonoGame also suggests this tool (that means I am not the only trying to figure out how to create those XNB files). At the moment my try was to contact this tool author and asking for some support.

I confess I was expecting some more organization from MonoGame. I am really considering the suggestion to change the syllabus for another library. Even libgdx is more organized.

 

PR-Challenge: January 1st PR

Cross Posted from my Perl Blogs blog.

So, yeah, to make me more active in the Perl community I decided to join the Pull Request Challenge. I have a quite big number of modules to maintain, but sometimes it is good to look to some other people code to learn something.

My attribution for January was Data::ObjectDriver. I am not sure, yet, what this module is about, but I learned some stuff already, dealing with Module::Install. That was enough for a simple Pull Request [see here]. Hopefully it will be useful for other people as well. Also, hope it gets accepted.

Although this is enough for the Challenge, I expect, in the next days, to prepare at least one more Pull Request. So, stay tuned.

EDIT: The second pull request [here] did not take that much time. Fixed a test that was failing given new error message on DBD::SQLite.

Javascript Reversi

In the last two days I engaged in developing Reversi, just to learn how the minimax algorithm works. To make it easier to share, and remove GUI toolkit dependencies, my approach was using HTML (a simple page with a 8×8 table), three images (empty cell, black or white cells), a CSS file that fills empty cells or used cells, and highlights movement possibilities, and a couple of JavaScript files (jquery, a reversi-board.js file to handle the board as an object, a reversi.js file to handle the interface between the board and the HTML file, and finally a minimax.js file to handle the minimax algorithm.

At the moment the game is playable, and not too slow. The code can be optimized to make it faster. In the next couple of days I might do that.

Also, regarding the AI code, it can be made better. In one side, the minimax algorithm can try to analyze more moves in advance (only three at the moment), in the other, the board evaluation function can be made better as well.

If you wish to play, go ahead: http://eremita.di.uminho.pt/~ambs/reversi

Java User-Friendness

I can’t see how people say Java is an end-user language, whose applications are for general user usage…

SEVERE: Exception
javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	... 3 more
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more

---------

javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more
---------
org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)

Just great. Now I know exactly what to do. Cry!

Artificial Intelligence for Games errata

This year I am teaching Artificial Intelligence for Games. I grabbed some book PDFs from the Internet (yes, sorry, it would be impossible to buy all the books to choose one, and libraries around doesn’t have books in this thematic) and I chose a pair of books to buy. One of them is this Artificial Intelligence for Games, by Ian Millington and John Funge.

The book is quite complete, the language very accessible, full of code, lots of insights about that developing AI for games means. I really like the book, and I will continue to use in future years if they let me continue teaching this course.

Unfortunately the book is full of small typos and problems. There is an official errata available but it is very incomplete. I started writing my own errata (I’m not repeating the items in the official errata, just adding new errors I find) with some fixes, and some insights on some interpretation problems. I warned Ian Millington about my errata, and he will, hopefully, go through my errata items and decide if they should be included in the official errata. While Ian doesn’t have the time for that, I am sharing my own errata page. Note that I am not professional on this area and I might have misunderstood something…

Hiding the bird’s guts

Probably this is a stupid rant/question. If so, please clarify me. I can live without the insults. Really 🙂

OK, on to the relevant stuff. Twitter has a new OAuth authentication mechanism. To write an application able to post on twitter your application need to be registered and have a consumer key. That key is used to identify your application to twitter when requesting permissions to a user to post using her credentials.

Now, the problem is when your application is written in a scripting language, like Perl, Python, Ruby or anything similar. Will you insert this key verbatim in the source code? Then, when shipping your app, others can grab that token and use it as if it were your app. You can encrypt it, but you need to ship the decryption algorithm as well, so, making the key verbatim.

One of two things can be happening: or twitter guys are not good on this API thing, or I am being totally stupid.

DevC++ and their lack of discernment

If you know me, you know that I program mainly C and Perl, that my preferred editor is Emacs, and that I use mostly Mac OS X for that task.

But, I teach programming, and sometimes I teach programming to students that never heard of Linux or, worse, that never used the command line of Windows. Given this, I tend to search for simple solutions to help them do not deal with the command line so I can use more time for the task of learning how to program.

With that in mind, I decided to suggest a C IDE for windows. The main IDE (I think) is Visual Studio. Although it is paid, there are protocols between Microsoft and the universities to use their software for free for academic purposes. But the Visual Studio installation disc is some hundreds of megabytes. That is not very portable. Also, the application is quite heavy when running. I decided to search for an alternative, and found DevC++. It is just 10 megabytes of download, uses GCC (or MinGW), and works quite well.

It just have one big and stupid problem. Although DevC++ is being developed for more than a decade, their developers did not implement, yet, a pause mechanism for when you are running a console program. In their faq they suggest to add a ‘system(“PAUSE”)’ in the end of the code. That is just stupid! Why to have to add such a line in your code, just during development, and then remove it when you want to ship the application? It would be quite more interesting to have an option in the IDE to force that window not to close. Some other similar applications, like the Lazarus IDE for Pascal, include that option already.

Now I need to decide if I should go back to Visual Studio, if I should explain why DevC++ doesn’t work properly, and explain how to add a pause at the end of the application, of if I should go back and teach students how to test their applications right from the command line.

CSS Cheat Sheet

CSS Cheat Sheet

CSS Cheat Sheet

I teach XML, DTD and the like, and I teach (or show and make students use) CSS for XML. It doesn’t work properly on all browsers, it doesn’t work consistently on all browsers, it doesn’t do everything web publishing needs. But it is a good approach to add some style and usefulness to XML without teaching XSLT.

Normally I give my students a CSS Cheat Sheet. Usually it is the CSS Cheat Sheet v2 from Added Bytes. This time I googled some more time searching for a better one. Basically, Added Bytes cheat sheet present keywords for CSS properties, but doesn’t describe valid values.

In this quest, I found what I think it the best (ok, one of the best) CSS Cheat Sheet available in the Internet. It is from “A Coding Fool” webpage. It is two pages but I do not see that as a problem, given now most printers do duplex and, if it doesn’t, you can always do that manually. Is just one sheet of paper…

Pascal: parameters by reference

I posted some time ago about Pascal, and the nice (and worst) things that Pascal has in its language. I discovered yet another cool thing. Unlike C, where you can pass parameters to functions by value, or using a pointer (and therefore, as reference), in Pascal you can use a value, you can use a pointer, or declare a parameter as a variable. This is similar to passing by pointer, but with a cleaner syntax.

Note the difference between

  1. procedure foo(bar: integer);
  2.    begin
  3.        bar := 10;
  4.    end;

and

  1. procedure foo(var bar: integer);
  2.   begin
  3.      bar := 10;
  4.   end;

The first procedure does not change anything in the outside world, while the second changes the value of the variable passed as argument.

As expected, the compiler raises an error if you call this second procedure with a constant integer.

Pascal: The Good, the Bad and the Ugly

As I posted before, I am teaching Pascal. I could discuss the relevance on teaching this language in this decade, but that is not my concern. I would like just to point The Good, the Bad and the Ugly I find in Pascal.

The Good: Pascal evolved and is a high level language. You have auto-growing strings (ok, with a size limit), you have arrays indexed by characters, integers or enumerated data types. That is good!

The Bad: Pascal syntax continues to be a mess. Begin and End keywords make the code big, the attribution with ‘:=’ makes it easy to type errors, and the low precedence of logic operators make me angry.

The Ugly: I can’t find a clean way to try opening a file without crashing the application. The only method I found (check the bottom of http://www.learn-programming.za.net/programming_pascal_learn10.html needs you to turn on and off compiler flags. That is annoying, stupid and decidedly too low level…