In this paper, the problem of primary scrambling code (PSC) allocation in wideband code-division multiple access (WCDMA) self-configuring small cell networks is studied using tools from game theory. In this game, it is shown that when the number of available scrambling codes is larger than or equal to the number of small cells, globally optimal and individually optimal PSC allocations always exist and coincide with the set of Nash equilibria. In the converse case, it is shown that an individually optimal PSC allocation might not exist. However, the existence of a global optimal allocation is always ensured. Here, the notion of individual optimality corresponds to the case in which small cells cannot reduce their probabilities of code confusion by changing their own PSC choices. On the other hand, the notion of global optimality refers to the case in which no other PSC allocation can reduce the probability of code confusion. The second contribution is a pair of algorithms based on the notion of trial and error learning that allow the achievability of an individually optimal PSC allocation, if it exists, or a globally optimal allocation otherwise. Both algorithms present attractive properties independently of the network topology and the ratio between the numbers of PSCs and active small cells in the network.