Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is enemy / bot A.I. part of the model or controller in an MVC game

It could be part of the model because it's part of the business logic of the game.

It could be part of the controller because it could be seen as simulating player input, which would be considered part of the controller, right? Or would it?

What about a normal enemy, like a goomba in Mario?

UPDATE: Wow, that's really not the answer I was expecting. As far as I could tell, A.I. is an internal part of the autonomous game system, hence model. I'm still not convinced.

like image 364
Iain Avatar asked Dec 10 '08 17:12

Iain


People also ask

What does controller mean in MVC?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.

Is MVC a model?

MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software's business logic and display. This "separation of concerns" provides for a better division of labor and improved maintenance.


2 Answers

MVC works very well as an architecture for a large number of applications. Some applications may find that MVC works well for the external interfaces, especially User Interfaces as part of a more complex architecture.

If you find yourself trying to "force fit" a problem into a pattern, it probably isn't the right pattern. Use MVC for the UI - use other patterns (Message Bus, or Observer/Listener, etc...) or other OO techniques for the AI (@Bill the Lizard's suggestion of Strategy still applies).

Use your entire toolbox - not just the hammer. ;-)

like image 154
Ken Gentle Avatar answered Sep 23 '22 20:09

Ken Gentle


The enemy AI has a model - its intelligent innards that specify how to play the game - and it uses the controllers available to both human players and NPCs to manipulate its state in the game environment.

like image 27
David Koelle Avatar answered Sep 23 '22 20:09

David Koelle