It is currently 30 Oct 2025, 06:41
   
Text Size

Refactoring requests

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

Refactoring requests

Postby Max mtg » 26 Nov 2013, 11:24

I've started this topic to discuss and plan what needs to be changed about the code to make it more versatile, flexible, better, harder, faster and stronger.

Whenever anything needs to be changed in classes used by many other systems, please post your requests and suggestions here.


My first request and objective for now is to remove all references to forge.gui.* and swing from classes located in forge.game.* packages. The reason is quite simple: games should run without GUI to be able pass automated tests, simulate AI vs AI matches (will get handy for tournaments played with bots). So all classes from the game module are expected interact to with players via interface provided by PlayerController.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Refactoring requests

Postby ptx » 26 Nov 2013, 11:56

As I've also posted in the testing topic, reworking the current PlayerController system so that there is a clear(er) separation between :
  • Making choices -> this is a job for the ui (whether it be gui, ai, network, test, ...)
  • Enumerating options to choose from -> this is somewhat tricky, the logic for doing this should definitely live in the rules engine (so it is not duplicated etc), but in some cases it might make more sense to have the ui code invoke the code, instead of having the rules engine prepare and pass the options to the ui
  • Validating choices -> this is obviously a job for the rules engine (though the ui may still want to also invoke the rules engine to do this for presentation or prediction reasons, but that should merely be something extra, the rules engine should never rely on the ui doing this)
  • Modifying the game state to implement the choice -> this is purely the rules engine's job, should not be accessible from ui

So PlayerController implementations should never directly modify the Game object (or the combat object etc). Instead they should receive a read-only version (or at the very least treat the normal version as read-only), as well as an object representing the choice to be made. They can then modify this latter object (or return a new object) to specify the action to be taken, so that after the method call has finished, the rules engine can validate that object, and make the required changes to the game state.
So to cast a spell, the PlayerController no longer handles paying costs and putting on the stack etc itself, instead it returns an object representing how costs should be payed, and the rules engine validates that and handles the rest.
ptx
 
Posts: 11
Joined: 07 Nov 2013, 04:28
Has thanked: 0 time
Been thanked: 2 times

Re: Refactoring requests

Postby Max mtg » 29 Nov 2013, 04:05

ptx, this is absolutelly correct, but involves a very large amount of code to handle. So, do proceed with refactoring if you feel confident about it.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Refactoring requests

Postby drdev » 29 Nov 2013, 05:18

Max mtg wrote:ptx, this is absolutelly correct, but involves a very large amount of code to handle. So, do proceed with refactoring if you feel confident about it.
Can we hold off any more major refactoring until after tomorrow's release?
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Refactoring requests

Postby Max mtg » 29 Nov 2013, 08:18

drdev wrote:
Max mtg wrote:ptx, this is absolutelly correct, but involves a very large amount of code to handle. So, do proceed with refactoring if you feel confident about it.
Can we hold off any more major refactoring until after tomorrow's release?
That's just impossible to handle such a huge amount of refactoring in under 1 day.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 8 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 8 guests

Login Form