Back
Close
  • 29

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

In football (Soccer), the offside rule is one of the most contentious and a frequent topic of heated debate among fans. The advent of Video Assistant Referee (VAR) technology is supposed to reduce the offside uncertainty.

You are tasked with implementing the VAR system for identifying offside situations, based on data supplied by both the video (screenshot at the moment the ball is played) and the human referees (players eventually considered as "actively involved" once the ball is released).


Offside position
- A player is in an offside position if, at the moment the ball is released, they are nearer to the opponent's goal line than both the ball and the second last opponent (the last opponent is usually, but not necessarily, the goalkeeper).
- There is no offside position if the play (the last ball release) is a throw-in.
- The offside rule applies only to players in the opponent's half of the pitch. This makes sense since you can't be offside if you are positioned in your own camp. Only players who "transgress" the middle line and "attack" the other camp might fall in an offside trap :)


Offside offence
Being in an offside position is not an offence in itself, but a player so positioned when the ball is played by a teammate can be judged guilty of an offside offence if they are "involved in active play" (i.e. receive the ball, interfere with an opponent, ...). In this case, the referee calls offside.


VAR data
The input provides information (screenshot) on how all the players of TEAM_A and TEAM_B are positioned in the pitch the moment the ball is played.
The screenshot is encoded using the characters #.aAbBoO as follows:
# for boundary lines (goal lines, 18-yard box, touch lines, half-way line)
. for unoccupied parts of the pitch
a for players of the TEAM_A
b for players of the TEAM_B
A for "active" players of the TEAM_A (as judged by a human referee), if any
B for "active" players of the TEAM_B (as judged by a human referee), if any
o or O for the ball at the moment it is released by a player from TEAM_A or TEAM_B respectively.
- If the ball is represented by lowercase o, then the attacking team is TEAM_A and the opponent team is TEAM_B. if the ball is uppercase O, then it is the other way around.
- The size of the pitch (screenshot) is width=51 x height=15. The half-way line is therefore at X=51//2=25.
- TEAM_A attacks from right to left. The TEAM_A's half of the pitch is therefore 25 <= X <= 50 and its second-to-last is the player with the 2nd highest X coordinate.
- TEAM_B attacks from left to right. The TEAM_B's half of the pitch is therefore 0 <= X <= 25 and its second-to-last is the player with the 2nd lowest X coordinate.
- If the ball is at the touch line, i.e. the first or the last row (Y = 0 or Y=14), then it is a throw-in.


Requested output
You always need to print two lines:
Line 1: No player in an offside position. or n player(s) in an offside position., where n is the number of players offside.
Line 2: VAR: OFFSIDE! if an offside position should be sanctioned (offside offence) or VAR: ONSIDE! otherwise.
Input
Lines 1 to 15: string of 51 characters among #.aAbBoO to represent a row of the VAR screenshot
Output
Line 1: No player in an offside position. or n player(s) in an offside position., where n is the number of players offside.
Line 2: VAR: OFFSIDE! if an offside position should be sanctioned (offside offence). Otherwise: VAR: ONSIDE!
Constraints
Example
Input
###################################################
#........................#........................#
#.......................a#........................#
#...............b.o......#........................#
#######..................#..................#######
#.....#......a...b.......b...........a......#.....#
#.....#......b.......a..a#....b.............#.....#
#..b..#........A.........#..................#.....#
#.....#...........b....b.#..............a...#.....#
#.....#....A.............#..................#.....#
#######.......b..........#..................#######
#.....................a..#.......b................#
#........................#..........a.............#
#........................#....b...................#
###################################################
Output
1 player(s) in an offside position.
VAR: OFFSIDE!

A higher resolution is required to access the IDE