Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code:
- let passable gstate (row, col) =
- let t = tile_of_int (gstate.tmap.(row).(col).content) in
- not ((t = `Water) || (t = `Food))
- ;;
- Some might prefer:
- let passable gstate (row, col) =
- let landmap = gstate.tmap in
- let lm_row = landmap.(row) in
- let tile = lm_row.(col) in
- let v = tile_of_int tile.content in
- not ((v = `Water) || (v = `Food))
- ;;
- In this case I don't see any benefit in expanding the value-accessing line.
- Consider this, though:
- let visible_and_passble gstate (row, col) =
- let tile = gstate.tmap.(row).(col) in
- let terrain = tile_of_int tile.content in
- let visible = (tile.seen > 0) in
- visible && (not ((terrain = `Water) || (terrain = `Food)))
- ;;
- Here we refer to 'tile' twice after its initial declaration, so the above could be considered better than:
- let visible_and_passble gstate (row, col) =
- let terrain = tile_of_int gstate.tmap.(row).(col).content in
- let visible = (gstate.tmap.(row).(col).seen > 0) in
- visible && (not ((terrain = `Water) || (terrain = `Food)))
- ;;
Add Comment
Please, Sign In to add comment