0

I'm new to OCL and currently trying to figure out how to do invariants. I attached a picture with the diagramm I'm working on.

https://i.stack.imgur.com/daQQN.jpg

The invariants that I'm trying to resolve are :

a) A player has 0 or 2 cards in hand.

   Context Player
   inv i1: self.card->size()=0 or self.card->size()=2

b) A player, who has not played any rounds, can't have more Game Capital than the maximal Buy-In of the table.

 Context Player
   inv i2: self.numberOfRounds=0 implies (self.gameCapital < self.Table.maxBuyIn)

c) At every table can be only players that belong to different users

   Context Player
   inv i3: Player.UserAccount.allInstances().userID->isUnique()

I'm not sure if 'allInstances()' is supposed to go after Player or after PlayerAccount. And I don't know what I'm supposed to do with the 'At every table' part of the text.

There are two more points that I really don't know how to do.

d) In the deck are 52 cards, which differ from eachother through color or value

e) The inputs of all players that still have cards in the hand are equal when bidDone True.

Can you please tell me if what I've done until now is correct and maybe some advice or solution for d) and e)?

Any help is appreciated!

Rob
  • 26,989
  • 16
  • 82
  • 98

1 Answers1

0

Seems plausible, but I would recommend sensible names, since a validation tool will tend to report that e.g Constraint Player::i2 is not satisfied for ...

b) looks to have a < / <= bug

c) allInstances takes a type source so "Player." is wrong. allInstances is generally very inefficient to execute so should only be used as a last resort. In your case it is clearly wrong since your scope is "at every Table". You should be using context Table and then reasoning about the players at the table.

d) if you rephrase "differ from" as "is unique with respect to", you can perhaps see how you could use a Tuple of color+value as the basis for uniqueness.

e) no idea what an input is, but it just seems like a cascade of implies clauses.

Ed Willink
  • 1,205
  • 7
  • 8