Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 23b88cc

Browse files
valeriyvandan-zheng
authored andcommitted
Uses switch instead of ifs (#219)
1 parent b3a1f42 commit 23b88cc

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Catch/main.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ extension CatchAgent {
8989
func perfectAction(for observation: Observation) -> Action {
9090
let paddleX = observation.scalars[0]
9191
let ballX = observation.scalars[1]
92-
if paddleX > ballX {
93-
return .right
94-
} else if paddleX < ballX {
95-
return .left
92+
switch paddleX {
93+
case ballX: return .none
94+
case ..<ballX: return .left
95+
default: return .right
9696
}
97-
return .none
9897
}
9998

10099
/// Returns a random action.

0 commit comments

Comments
 (0)